How can I have a user select multiple options and quantity of each?

22 ビュー (過去 30 日間)
DKonk
DKonk 2022 年 7 月 27 日
コメント済み: DKonk 2022 年 7 月 27 日
I am trying to write a function that has the user select which options they want and how many. So either in a display window or the command window, it would show something like:
Tanks: ____
Infantry: ____
Artillery: ____
Fighters: ____
Then the user could input numbers into the window which would result in an array [1, 10, 0, 2] indicating 1 tank, 10 infantry, 0 artillery, and 2 fighters.
I have tried uicontrol and although I didn't get it to work, I may be using it wrong. A display window like "menu" would be ideal, but the command window works just as well. I would supply my script that I currently have, but I really have nothing so far. Any insight is appreciated.

採用された回答

Kevin Holly
Kevin Holly 2022 年 7 月 27 日
You can use inputdlg.
If you want to make something more sophisticated, you could create an app with App Designer.
  3 件のコメント
Kevin Holly
Kevin Holly 2022 年 7 月 27 日
You can convert it to a numeric array as such:
x = {'2';'0';'3';'0'}
x = 4×1 cell array
{'2'} {'0'} {'3'} {'0'}
str2double(x)
ans = 4×1
2 0 3 0
DKonk
DKonk 2022 年 7 月 27 日
Thanks!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by