How can I suppress or change the error message 'Undefined function or variable'
3 ビュー (過去 30 日間)
古いコメントを表示
I am using the user request ‘input’ function to gather some data which is all supposed to be numeric. Obviously if the user enters a letter Matlab throws up the above error due to a data type clash:
Please enter a number: t
Error using input
Undefined function or variable 't'.
Error in finaltest (line 5)
number= input('Please enter a number:
');
Please enter a number:
I would like to suppress this error or, even better, change it to one of my own.
I have tried to find the error identifier, but to no avail:
EDU>> lasterror
ans =
message: [1x135 char]
identifier: [1x24 char]
stack: [1x1 struct]
Is it even possible to change this error?
Thanks in advance
Steve
0 件のコメント
採用された回答
Vivek Selvam
2013 年 10 月 23 日
編集済み: Vivek Selvam
2013 年 10 月 23 日
You can try this:
number = '';
% str2double returns NaN if input is not a real or complex scalar value
while isnan(str2double(number))
number= input('Please enter a number: ','s'); % get input as string
end
disp(['You entered ' number]);
number = str2double(number);
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Structures についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!