How can i determine error in matlab by using error loop without try catch or other loops?

1 回表示 (過去 30 日間)
My code only includes numbers. If someone donot gives a numbers in input, this code shows screen like ERROR but code should continue to work Thanks,

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2016 年 4 月 30 日
編集済み: Azzi Abdelmalek 2016 年 4 月 30 日
a=input('enter a number N','s')
b=str2num(a)
if isempty(b)
'Error'
'presse any key to cotinue'
pause
end
  1 件のコメント
Walter Roberson
Walter Roberson 2016 年 4 月 30 日
編集済み: Walter Roberson 2016 年 4 月 30 日
str2double would be better for restricting to numbers. you would check for nan rather than isempty

サインインしてコメントする。

その他の回答 (1 件)

ahmet ozdemir
ahmet ozdemir 2016 年 4 月 30 日
Thanks for comment. Actually, it is not empty. For example Enter the number:4+5 9 Enter the number:4-9 -5 Enter the number:4+ (((()))) ERROR Enter the number:h+4 ERROR
If input includes h and empty parenthesis, this code will gives error. I finished all steps but i didnot do error part

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by