1 Pages (8 items)
numbers and vectors - Messages
#1 Posted: 1/14/2012 11:51:27 PM
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 0or 1 in case var is a number)
regards
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
regards
If you like my plugins please consider to support the program buying a license; for personal contributions to me: paypal.me/dcprojects
#2 Posted: 1/15/2012 2:41:11 AM
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
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
When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
#3 Posted: 1/15/2012 5:11:19 PM

at the moment I'm using this workaround

If you like my plugins please consider to support the program buying a license; for personal contributions to me: paypal.me/dcprojects
1 users liked this post
Radovan Omorjan 1/15/2012 5:58:00 PM
#4 Posted: 1/15/2012 6:07:35 PM
Hello,
There is a minor problem with your workaround. Suppose you have a matrix with only one element (this is allowed in SMath)
[MATH=eng]b←mat(5,1,1)[/MATH]
[MATH=eng]el(b,1)=5[/MATH]
[MATH=eng]el(b,1,1)=5[/MATH]
Your function will not recognize it as an array. It may cause problems sometimes, isn't it?
[MATH=eng]IsArray(b)=0[/MATH]
Regards,
Radovan
EDIT: On the other hand, every array is made by using mat() function i.e.
[MATH=eng]A←mat(1,2,1,3,2,2)[/MATH]
num2str( A )="mat(1,2,1,3,2,2)"
[MATH=eng]b←mat(5,1,1)[/MATH]
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.
There is a minor problem with your workaround. Suppose you have a matrix with only one element (this is allowed in SMath)
[MATH=eng]b←mat(5,1,1)[/MATH]
[MATH=eng]el(b,1)=5[/MATH]
[MATH=eng]el(b,1,1)=5[/MATH]
Your function will not recognize it as an array. It may cause problems sometimes, isn't it?
[MATH=eng]IsArray(b)=0[/MATH]
Regards,
Radovan
EDIT: On the other hand, every array is made by using mat() function i.e.
[MATH=eng]A←mat(1,2,1,3,2,2)[/MATH]
num2str( A )="mat(1,2,1,3,2,2)"
[MATH=eng]b←mat(5,1,1)[/MATH]
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.
When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
#5 Posted: 1/15/2012 8:35:05 PM
with 1x1 vectors I don't have problems (I'm using SMath 0.90)
Now I've replaced
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.sm
Now I've replaced
num2str(length())[/code] with less expensive [code]num2str()[/code] and I've replaced [code]findstr("l"
[/code] with [code]findstr("m"
and I've fixed a little bug with words that contains the findstr argument and a big bug with strings with whitespaces introducing
IsString()
edit: here there is the file with the two functions IsArray.sm
If you like my plugins please consider to support the program buying a license; for personal contributions to me: paypal.me/dcprojects
#6 Posted: 1/15/2012 9:31:14 PM
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
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!"
#7 Posted: 1/15/2012 11:15:48 PM
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)
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)
ans:=findstr(_e,"mat("
+1
When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
#8 Posted: 1/16/2012 4:17:25 AM
Great hints 

If you like my plugins please consider to support the program buying a license; for personal contributions to me: paypal.me/dcprojects
1 Pages (8 items)
-
New Posts
-
No New Posts