Easy question comparing strings

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

 채택된 답변

Tom
Tom 2013년 6월 26일

0 개 추천

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개)

카테고리

도움말 센터File Exchange에서 Numeric Types에 대해 자세히 알아보기

태그

질문:

JP
2013년 6월 26일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by