How can I limit a set of input data, 6 values, to a min and max point and as an integer

9 ビュー (過去 30 日間)
Andre du Plessis
Andre du Plessis 2020 年 2 月 17 日
回答済み: KSSV 2020 年 2 月 18 日
I am writing a piece of code requesting the user to submit 6 integer numbers in the range [1,59]. I want to make it so that if the user submits an value outside the range or a non integer, the code breaks and displays an error message saying invalid numbers chosen.
  3 件のコメント
James Tursa
James Tursa 2020 年 2 月 17 日
Hint: Look at the min( ), max( ), and round( ) functions.
Andre du Plessis
Andre du Plessis 2020 年 2 月 18 日
prompt = {'1st','2nd','3rd','4th','5th','6th'};
dlgtitle = 'Choose 6 integers between 1-59';
user1 = inputdlg(prompt,dlgtitle,dims)';
user = round(str2double(user1))

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

採用された回答

KSSV
KSSV 2020 年 2 月 18 日
if min(user)<1 || max(user)>59
error("Check the input")
endif

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by