フィルターのクリア

Is there a specific function forcing user to select a particular option?

5 ビュー (過去 30 日間)
Kubilay ISIK
Kubilay ISIK 2015 年 5 月 4 日
コメント済み: Walter Roberson 2015 年 5 月 5 日
Hi,
I want to force user to select a particular option in a console program.
For example, the script might ask which pet does the user have and force him to type cat, dog, bird or other. Is there a specific function for this? Such as:
a_fancy_function('Which pet do you have? (cat, dog, bird, other)', 'cat','dog','bird','other');
Thank you.

回答 (4 件)

Walter Roberson
Walter Roberson 2015 年 5 月 4 日
See example 2 of menu()
  2 件のコメント
Titus Edelhofer
Titus Edelhofer 2015 年 5 月 4 日
Nice. Never seen before ...
Walter Roberson
Walter Roberson 2015 年 5 月 5 日
It is the only graphics function that I can think of that is simulated as text when there is no graphics. An oddity that is easily forgotten.

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


Titus Edelhofer
Titus Edelhofer 2015 年 5 月 4 日
Hi,
no, for a console program there is no function for this. You will need to use the function input and verify what has been typed by the user (in a while loop with e.g. three attempts at most).
For a non console program you can use listdlg.
Titus

Purushottama Rao
Purushottama Rao 2015 年 5 月 4 日
you can use
i= menu(' Which Pet do You Have?','cat','dog','bird','other');
Which results in a pop up menu with options which returns the values for i as
i=1 if cat is selected.. i=2 if dog is selected.. i=3 if bird is selected.. 1=4 for other ..
  2 件のコメント
Walter Roberson
Walter Roberson 2015 年 5 月 4 日
This works differently on a console program, as it does not pop-up if there are no graphics. It will, however, happen to work, as menu() detects the lack of graphics and uses a text prompt instead. This is as shown in example 2 of the documentation for menu(), as I indicated in my answer.
Purushottama Rao
Purushottama Rao 2015 年 5 月 5 日
Yeah, i fully agree with you. I tried out in console program and found not working. Thanks for the information.

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


Kubilay ISIK
Kubilay ISIK 2015 年 5 月 4 日
Thank you all for your urgent responses.
  1 件のコメント
Titus Edelhofer
Titus Edelhofer 2015 年 5 月 4 日
Hi,
I would suggest to mark Walters answer as "the" answer ...
Titus

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

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by