Rank: Advanced Member Groups: Registered, Advanced Member Joined: 13/01/2012(UTC) Posts: 2,648 Location: Italy Was thanked: 1332 time(s) in 876 post(s)
|
Hi, I think will be useful a function that show if a variabile it's a number (something like the classic isNaN() or also length(var) may be modified to return 0 or 1 in case var is a number) regards Edited by user 18 October 2012 16:46:18(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 |
|
|
|
Rank: Administration Groups: Registered, Advanced Member Joined: 23/06/2009(UTC) Posts: 1,740 Was thanked: 318 time(s) in 268 post(s)
|
Hello, I agree. As far as I know, there is only IsString() and IsDefined() functions among IsThisorThat() functions available. I believe that other functions like IsArray() or IsScalar() would be useful. Regarding your question, IsString(arg) function will return 1 if the argument variable -arg- is string variable or function returning string, 0 otherwise (number, scalar, vector, matrix, function returning the ones). Regards, Radovan Edited by user 15 January 2012 09:42:41(UTC)
| Reason: Not specified |
When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!" |
|
|
|
Rank: Advanced Member Groups: Registered, Advanced Member Joined: 13/01/2012(UTC) Posts: 2,648 Location: Italy Was thanked: 1332 time(s) in 876 post(s)
|
at the moment I'm using this workaround Edited by user 16 January 2012 00:13: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 |
1 user thanked Davide Carpi for this useful post.
|
|
|
Rank: Administration Groups: Registered, Advanced Member Joined: 23/06/2009(UTC) Posts: 1,740 Was thanked: 318 time(s) in 268 post(s)
|
Hello, There is a minor problem with your workaround. Suppose you have a matrix with only one element (this is allowed in SMath) b←mat(5,1,1)el(b,1)=5el(b,1,1)=5Your function will not recognize it as an array. It may cause problems sometimes, isn't it? IsArray(=0Regards, Radovan EDIT: On the other hand, every array is made by using mat() function i.e. A←mat(1,2,1,3,2,2)num2str( A )="mat(1,2,1,3,2,2)"b←mat(5,1,1)num2str( b )="mat(5,1,1)"Unfortunately, I did not figure out how to use all of this to make a IsArray() function which will work with string, scalar and array arguments. Edited by user 16 January 2012 01:42:04(UTC)
| Reason: Not specified |
When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!" |
|
|
|
Rank: Advanced Member Groups: Registered, Advanced Member Joined: 13/01/2012(UTC) Posts: 2,648 Location: Italy Was thanked: 1332 time(s) in 876 post(s)
|
with 1x1 vectors I don't have problems (I'm using SMath 0.90) Now I've replaced with less expensive and I've replaced with and I've fixed a little bug with words that contains the findstr argument and a big bug with strings with whitespaces introducing edit: here there is the file with the two functions IsArray.smEdited by user 16 January 2012 03:47:39(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 |
|
|
|
Rank: Administration Groups: Registered, Advanced Member Joined: 23/06/2009(UTC) Posts: 1,740 Was thanked: 318 time(s) in 268 post(s)
|
Hello, Thank you for your efforts. It is a bit tricky and unusual, but works most of the time. What do I mean by that. Just look at the picture (your function used) and it seems to be problematic for the arrays with units and nested arrays. Maybe some more adjustments? Regards, Radovan |
When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!" |
|
|
|
Rank: Administration Groups: Registered, Advanced Member Joined: 23/06/2009(UTC) Posts: 1,740 Was thanked: 318 time(s) in 268 post(s)
|
Hello, This might be useful, I think. Regards, Radovan EDIT: I just replaced the ans with this expression and it works as well with scalar and units (problem was with scalar and units including 'm in them) Code:ans:=findstr(_e,"mat(")+1
Edited by user 16 January 2012 09:02:13(UTC)
| Reason: Not specified |
When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!" |
|
|
|
Rank: Advanced Member Groups: Registered, Advanced Member Joined: 13/01/2012(UTC) Posts: 2,648 Location: Italy Was thanked: 1332 time(s) in 876 post(s)
|
Great hints Edited by user 18 October 2012 16:47:17(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 |
|
|
|
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.