MATLAB Answers

JP
0

Easy question comparing strings

JP
さんによって質問されました 2013 年 6 月 26 日
Hello I have the following code which doesn't work. The problem is Im trying to compare the value "NaN" which I guess isnt a string?...to the value of X. Let me know how to fix it thanks!
str = input('Please enter a number \n\n','s');
X = str2double(str);
test=strcmp(X,'NaN');
if test == 1
disp('That was not a valid number');
else
disp('Here is your number')
disp(X)
end

  0 件のコメント

サインイン to comment.

タグ

1 件の回答

Tom
回答者: Tom
2013 年 6 月 26 日
 採用された回答

You can just ISNAN instead:
str = input('Please enter a number \n\n','s');
X = str2double(str);
if isnan(X)
disp('That was not a valid number');
else
disp('Here is your number')
disp(X)
end

  0 件のコメント

サインイン to comment.



Translated by