I want to throw the error that comes with entering a non number in a numeric only input
15 ビュー (過去 30 日間)
古いコメントを表示
n = input('Please enter a number:\n');
I get this error and I want to throw it and write another error:
Error using input
Unrecognized function or variable 'k'.
Error in eer (line 1)
n = input('Please enter your name:\n');
0 件のコメント
採用された回答
Wan Ji
2021 年 8 月 30 日
n = str2num(input('Please enter a number:\n','s'));
if(isempty(n))
error('You are entering a non number in a numeric only input')
end
10 件のコメント
Wan Ji
2021 年 8 月 30 日
n = input('Please enter a number:\n','s');
if(isempty(n))
error('You are entering nothing')
elseif(isempty(str2num(n)))
error('You are entering a non number in a numeric only input')
end
n = str2num(n);
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Multirate Signal Processing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!