# Only gu values tu ?

38 views (last 30 days)
Steven Thies on 18 Feb 2021
Commented: Rena Berman etwa 16 Stunden ago
Hello Matlab community,
i created a script and everything works but i want to add that the script accepts also only integer values for m. How can i do this?
i = 0;
while isnan (str2double(m)) == true || str2double(m)<0
if isnan (str2double(m)) == true || str2double(m)<0
i = i+1;
if i == 4
return
end
else
break
end
end
##### 2 CommentsShowHide 1 older comment
Rena Berman etwa 16 Stunden ago

Les Beckham on 19 Feb 2021
To test for integer values of double numbers (doubles are the default numeric type in Matlab), I would suggest using mod(m,1).
So, in your case, replace "isnan (str2double(m)) == true || str2double(m)<0" with "mod(m,1) ~= 0" to detect a number that is not an integer.
Of course your code does nothing whether the test passes or fails so I'm not sure what the point is. I assume you have left some things out?

Walter Roberson on 19 Feb 2021
positive integers have the property that all of their characters are one of '0','1','2','3','4','5','6','7','8','9', or '+'... unless you want to accept exponential notation as well, in which case the characters might also be 'd', 'D', 'e', 'E', '.', or '-' .
Les Beckham on 19 Feb 2021