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 Davide Carpi  
#1 Posted : 15 January 2012 06:51:27(UTC)
Davide Carpi


Rank: Advanced Member

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

Was thanked: 1331 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

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

Offline omorr  
#2 Posted : 15 January 2012 09:41:11(UTC)
omorr


Rank: Administration

Groups: Registered, Advanced Member
Joined: 23/06/2009(UTC)
Posts: 1,740
Man
Serbia

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!"
Offline Davide Carpi  
#3 Posted : 16 January 2012 00:11:19(UTC)
Davide Carpi


Rank: Advanced Member

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

Was thanked: 1331 time(s) in 876 post(s)
Good

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
thanks 1 user thanked Davide Carpi for this useful post.
on 16/01/2012(UTC)
Offline omorr  
#4 Posted : 16 January 2012 01:07:35(UTC)
omorr


Rank: Administration

Groups: Registered, Advanced Member
Joined: 23/06/2009(UTC)
Posts: 1,740
Man
Serbia

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)=5
el(b,1,1)=5

Your function will not recognize it as an array. It may cause problems sometimes, isn't it?

IsArray(Cool=0

Regards,
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!"
Offline Davide Carpi  
#5 Posted : 16 January 2012 03:35:05(UTC)
Davide Carpi


Rank: Advanced Member

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

Was thanked: 1331 time(s) in 876 post(s)
with 1x1 vectors I don't have problems (I'm using SMath 0.90)


Now I've replaced
Code:
num2str(length())
with less expensive
Code:
num2str()
and I've replaced
Code:
findstr("l")
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
Code:
IsString()


edit: here there is the file with the two functions IsArray.sm

Edited 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
Offline omorr  
#6 Posted : 16 January 2012 04:31:14(UTC)
omorr


Rank: Administration

Groups: Registered, Advanced Member
Joined: 23/06/2009(UTC)
Posts: 1,740
Man
Serbia

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? Good

Regards,
Radovan
When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
Offline omorr  
#7 Posted : 16 January 2012 06:15:48(UTC)
omorr


Rank: Administration

Groups: Registered, Advanced Member
Joined: 23/06/2009(UTC)
Posts: 1,740
Man
Serbia

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!"
Offline Davide Carpi  
#8 Posted : 16 January 2012 11:17:25(UTC)
Davide Carpi


Rank: Advanced Member

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

Was thanked: 1331 time(s) in 876 post(s)
Great hints Clap

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
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.