Welcome Guest! To enable all features please Login. New Registrations are disabled.

Notification

Icon
Error

Login


Options
Go to last post Go to first unread
Offline Alex M.  
#1 Posted : 03 January 2017 03:33:38(UTC)
Alex M.


Rank: Advanced Member

Groups: Registered
Joined: 03/03/2014(UTC)
Posts: 418
Canada

Was thanked: 125 time(s) in 96 post(s)
I would like to share an example of function that extracts rows from a data table based on set value in selected columns:
VLOOKUPdataparse.sm (18kb) downloaded 48 time(s).
vlookup1.png
vlookup2.png
thanks 1 user thanked Alex M. for this useful post.
on 03/01/2017(UTC)

Wanna join the discussion?! Login to your SMath Studio Forum forum account. New Registrations are disabled.

Offline Alex M.  
#2 Posted : 03 January 2017 03:39:38(UTC)
Alex M.


Rank: Advanced Member

Groups: Registered
Joined: 03/03/2014(UTC)
Posts: 418
Canada

Was thanked: 125 time(s) in 96 post(s)
I do need help with an interesting behaviour of a matrix definition:

If an element of a defined matrix contains a user defined function with an undefined parameter it may inthrow an error similar to here (same SMath file as above):

matrixBug_ElementContainsCustomFuction.png

I would expect the function with undefined parameter to return itself instead of giving an error code.
Offline Davide Carpi  
#3 Posted : 03 January 2017 13:06:30(UTC)
Davide Carpi


Rank: Advanced Member

Groups: Registered, Advanced Member
Joined: 13/01/2012(UTC)
Posts: 2,647
Man
Italy
Location: Italy

Was thanked: 1329 time(s) in 875 post(s)
Very nice Good

I think the issue comes out because there isn't a way to stop the preprocessing in user-defined functions when you pass an unknown (and an unknown is not a valid input).

A workaround that might be useful even to avoid the use of other functions is to use a string as input in the second row, and a check in your lookup like this:

2017-01-03 11_03_34-SMath Studio - [VLOOKUPdataparse.sm].png

2017-01-03 11_04_37-SMath Studio - [VLOOKUPdataparse.sm].png

Edited by user 03 January 2017 13:08:28(UTC)  | Reason: Not specified

If you like my plugins consider to support SMath Studio buying a plan; to offer me a coffee: paypal.me/dcprojects
thanks 2 users thanked Davide Carpi for this useful post.
on 03/01/2017(UTC),  on 03/01/2017(UTC)
Offline Alex M.  
#4 Posted : 03 January 2017 15:06:46(UTC)
Alex M.


Rank: Advanced Member

Groups: Registered
Joined: 03/03/2014(UTC)
Posts: 418
Canada

Was thanked: 125 time(s) in 96 post(s)
Davide,

Is the a reason why function like findstr() does not return itself when not all variables are defined? Similar to this:
http://en.smath.info/for...-function.aspx#post36158

Also I am not sure if this is similar, but after I modified my excel_IO() function to return FALSE if undefined variables were present it would preprocess correctly with undefined variables when passed as an argument to a user defined function (you and I had an email discussion about this).

P.S.: the reason why a more general solution is desired is because a one might want to implement a more complex boolean check, than <>=!

Edited by user 03 January 2017 16:22:57(UTC)  | Reason: Not specified

Offline Davide Carpi  
#5 Posted : 03 January 2017 18:37:22(UTC)
Davide Carpi


Rank: Advanced Member

Groups: Registered, Advanced Member
Joined: 13/01/2012(UTC)
Posts: 2,647
Man
Italy
Location: Italy

Was thanked: 1329 time(s) in 875 post(s)
Originally Posted by: Alex M. Go to Quoted Post
Is the a reason why function like findstr() does not return itself when not all variables are defined? Similar to this:
http://en.smath.info/for...-function.aspx#post36158

It is by design. However even returning itself, you will have always var=findstr(...) -> false -> ... (it doesn't prevents the strcont() function to be evaluated)

Originally Posted by: Alex M. Go to Quoted Post
Also I am not sure if this is similar, but after I modified my excel_IO() function to return FALSE if undefined variables were present it would preprocess correctly with undefined variables when passed as an argument to a user defined function (you and I had an email discussion about this).

Yes, but with functions created on the canvas this isn't possible Unsure

Originally Posted by: Alex M. Go to Quoted Post
P.S.: the reason why a more general solution is desired is because a one might want to implement a more complex boolean check, than <>=!

You can try with this:
2017-01-03 16_36_25-SMath Studio - [VLOOKUPdataparse(1).sm_].png

strcont() is defined locally to avoid the preprocessing on the canvas
try() function is added because when you use el(...) inside the lookup function, all the elements of the condition matrix are evaluated -> you have to allow any type of input as first argument or let it fails silently (because strrep requires strings); note that if the selected element of the condition matrix is the one that contains strcon() with a wrong type as first argument, the error string will trigger an error on bool#:eval(bool#*operand#), because operand# will be a string.

Edited by user 03 January 2017 18:45:32(UTC)  | Reason: Not specified

If you like my plugins consider to support SMath Studio buying a plan; to offer me a coffee: paypal.me/dcprojects
thanks 2 users thanked Davide Carpi for this useful post.
on 03/01/2017(UTC),  on 03/01/2017(UTC)
Offline Jean Giraud  
#6 Posted : 03 January 2017 21:06:28(UTC)
Jean Giraud

Rank: Guest

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 6,866
Canada

Was thanked: 981 time(s) in 809 post(s)
Alex,

The attached proposal is for fixed "credit".
It might be ranged via bolean.

Jean

Alex VLOOKUPdataparse.sm (34kb) downloaded 42 time(s).
thanks 1 user thanked Jean Giraud for this useful post.
on 03/01/2017(UTC)
Offline Alex M.  
#7 Posted : 03 January 2017 21:37:30(UTC)
Alex M.


Rank: Advanced Member

Groups: Registered
Joined: 03/03/2014(UTC)
Posts: 418
Canada

Was thanked: 125 time(s) in 96 post(s)
Originally Posted by: Jean Giraud Go to Quoted Post
Alex,

The attached proposal is for fixed "credit".
It might be ranged via bolean.

Jean

Alex VLOOKUPdataparse.sm (34kb) downloaded 42 time(s).



Thanks, Jean. I havent used "truth tables" yet; they seem to work quite well.
Offline Alex M.  
#8 Posted : 07 January 2017 02:53:23(UTC)
Alex M.


Rank: Advanced Member

Groups: Registered
Joined: 03/03/2014(UTC)
Posts: 418
Canada

Was thanked: 125 time(s) in 96 post(s)
Is there a quicker way to assemble a SMath matrix from rows than stack()?

In vb.net I can assemble 13x10000 SMath matrix in 3.3 seconds (excel_OUT), while stacking of 488 rows (13 elements each) into matrix within SMath takes 21 seconds

Thanks!

Edited by user 07 January 2017 02:55:46(UTC)  | Reason: Not specified

Offline Davide Carpi  
#9 Posted : 09 January 2017 13:49:47(UTC)
Davide Carpi


Rank: Advanced Member

Groups: Registered, Advanced Member
Joined: 13/01/2012(UTC)
Posts: 2,647
Man
Italy
Location: Italy

Was thanked: 1329 time(s) in 875 post(s)
Originally Posted by: Alex M. Go to Quoted Post
while stacking of 488 rows (13 elements each) into matrix within SMath takes 21 seconds


Hello Alex, can you attach an example where stack it is so slow?
If you like my plugins consider to support SMath Studio buying a plan; to offer me a coffee: paypal.me/dcprojects
Offline Jean Giraud  
#10 Posted : 09 January 2017 16:31:18(UTC)
Jean Giraud

Rank: Guest

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 6,866
Canada

Was thanked: 981 time(s) in 809 post(s)
Alex,

It depends what you assemble, and how.
Three examples attached.

Jean

Alex Assemble Matrix.sm (32kb) downloaded 28 time(s).
Offline Alex M.  
#11 Posted : 09 January 2017 19:52:25(UTC)
Alex M.


Rank: Advanced Member

Groups: Registered
Joined: 03/03/2014(UTC)
Posts: 418
Canada

Was thanked: 125 time(s) in 96 post(s)
Originally Posted by: Davide Carpi Go to Quoted Post
Originally Posted by: Alex M. Go to Quoted Post
while stacking of 488 rows (13 elements each) into matrix within SMath takes 21 seconds


Hello Alex, can you attach an example where stack it is so slow?


Here it is - I use EXCEL to input 10000 x 13 matrix into SMATH - 1.2 seconds. Vlookup() loop to stack 400 rows - 15 seconds. Vlookup() loop which does not stack anything is 3 seconds.

VLOOKUPslow.sm (28kb) downloaded 36 time(s).
DATA.xlsx (1,652kb) downloaded 48 time(s).

Edited by user 09 January 2017 20:02:23(UTC)  | Reason: Not specified

Offline Davide Carpi  
#12 Posted : 10 January 2017 03:06:51(UTC)
Davide Carpi


Rank: Advanced Member

Groups: Registered, Advanced Member
Joined: 13/01/2012(UTC)
Posts: 2,647
Man
Italy
Location: Italy

Was thanked: 1329 time(s) in 875 post(s)
Try this; basically removes all stack() calls to build the matrix after you check all the conditions. On my notebook is 50% faster than your.

VLOOKUPfast.sm (32kb) downloaded 99 time(s).

Edited by user 10 January 2017 03:08:24(UTC)  | Reason: Not specified

If you like my plugins consider to support SMath Studio buying a plan; to offer me a coffee: paypal.me/dcprojects
thanks 1 user thanked Davide Carpi for this useful post.
on 10/01/2017(UTC)
Offline Alex M.  
#13 Posted : 10 January 2017 03:13:40(UTC)
Alex M.


Rank: Advanced Member

Groups: Registered
Joined: 03/03/2014(UTC)
Posts: 418
Canada

Was thanked: 125 time(s) in 96 post(s)
Originally Posted by: Davide Carpi Go to Quoted Post
Try this; basically removes all stack() calls to build the matrix after you check all the conditions. On my notebook is 50% faster than your.

VLOOKUPfast.sm (32kb) downloaded 99 time(s).


Much better, thanks.

Could you explain how does the following exactly work:

resultrng#:el(data#,matches,range(1,cols(data#)))
Offline Davide Carpi  
#14 Posted : 10 January 2017 03:32:49(UTC)
Davide Carpi


Rank: Advanced Member

Groups: Registered, Advanced Member
Joined: 13/01/2012(UTC)
Posts: 2,647
Man
Italy
Location: Italy

Was thanked: 1329 time(s) in 875 post(s)
Originally Posted by: Alex M. Go to Quoted Post
Much better, thanks.

Could you explain how does the following exactly work:

resultrng#:el(data#,matches,range(1,cols(data#)))


You're welcome Good

It is this feature; in the 2nd argument of el(3) there are all the rows I want from first argument's matrix, as 3rd argument all the columns. The result is a matrix of the elements that fits both the requirements, in the given order.

Edited by user 10 January 2017 03:43:37(UTC)  | Reason: Not specified

If you like my plugins consider to support SMath Studio buying a plan; to offer me a coffee: paypal.me/dcprojects
Offline dxyont  
#15 Posted : 23 April 2021 06:20:54(UTC)
dxyont

Rank: Newbie

Groups: Registered
Joined: 18/04/2021(UTC)
Posts: 1
Location: Jakarta, Indonesia

thank you for sharing these function, lookup is another essential features of spreadsheet and could be better if it has to be include in standard distribution.

from vlookupfast.sm modification, may it be simplified for such a situation below. in case condition only use boolean 'equal to' as the same in any spreadsheet function.

vlookupsimplified.png

Edited by user 23 April 2021 06:26:24(UTC)  | Reason: Not specified

Offline Jean Giraud  
#16 Posted : 23 April 2021 21:29:41(UTC)
Jean Giraud

Rank: Guest

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 6,866
Canada

Was thanked: 981 time(s) in 809 post(s)
Originally Posted by: dxyont Go to Quoted Post
lookup is another essential features of spreadsheet and could be better if it has to be include in standard distribution.

There area dozen of lookup. If so many for so many applications.
Be more specific c/w *.sm document.

Lookup.PNG
Offline Jean Giraud  
#17 Posted : 23 April 2021 21:36:59(UTC)
Jean Giraud

Rank: Guest

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 6,866
Canada

Was thanked: 981 time(s) in 809 post(s)
... visit this intelligent/advanced lookup.

Utilities Matrix Locate Array1 Array2.sm (71kb) downloaded 29 time(s).
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.