Question about user input error

I have a simple piece of code that requires the input of a number. I want to prevent the user from accidentally enters a letter. I tried a while loop using intnan, but I'm stuck.

回答 (1 件)

John BG
John BG 2016 年 1 月 29 日

0 投票

try converting all inputs with uint.
If the return value of any input character does not belong to uint64('0123456789') then reject it, show a message or whatever you want to do.
John

カテゴリ

ヘルプ センター および File ExchangeParallel Computing Toolbox についてさらに検索

タグ

質問済み:

2016 年 1 月 29 日

回答済み:

2016 年 1 月 29 日

Community Treasure Hunt

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

Start Hunting!

Translated by