How to use if statement to test if it is a integer and real number?
古いコメントを表示
x = input('enter the number: ');
if isreal(x)
else
delete x
if isinteger(x)
delete x
end
end
I try to do it, but it doesn't work.How to make it? It just a part of the whole script. It requires to delete the number if it isn't a integer or real number.
採用された回答
その他の回答 (1 件)
Andrew Newell
2014 年 5 月 5 日
An integer is also a real number, so you only need one test. Also, if you want to delete numbers that are not real, you need to use a tilde (~) for negation. Assuming the input is always numeric, this will work:
x = input('enter the number: ');
if ~isreal(x)
clear('x');
end
2 件のコメント
Andrew Newell
2014 年 5 月 5 日
Judging by the multitude of errors in your short code snippet, I would strongly recommend working through at least one of the MATLAB Tutorials and Learning Resources.
Shi Yuhao
2014 年 5 月 5 日
カテゴリ
ヘルプ センター および File Exchange で Profile and Improve Performance についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!