how to display 'Not a number, try again'
2 ビュー (過去 30 日間)
古いコメントを表示
How do I display 'not a number, try again' when a word has been entered (eg. the letter a), without prducing error messages?
x = input('type a number: ')
t=isstring(x)
while t =1
disp('Not a number, try again')
x = input('type a number: ')
end
y = x*3
disp(y)
0 件のコメント
採用された回答
Walter Roberson
2020 年 4 月 24 日
msg = 'type a number: ';
while true
xs = input(msg, 's');
x = str2double(xs);
if ~isnan(x); break; end
disp('Not a number, try again')
end
3 件のコメント
Walter Roberson
2020 年 4 月 24 日
; is a statement separator that indicates that the expression before it is to be executed and any default display of results is not to be done. You can can also use comma instead, and when you do, the default output will appear.
There is a completely different use as well. Inside [] or {} indicates that a new row of values is to be started, such as [1 2;3 4] to define the array
1 2
3 4
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Data Import and Analysis についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!