create menu with input

40 ビュー (過去 30 日間)
Ali Tawfik
Ali Tawfik 2020 年 1 月 29 日
編集済み: Fangjun Jiang 2020 年 1 月 30 日
Hey all,
I have been trying to create menu with input command, I wanna the menu displays choices as buttons in a dialog box depends on how many element number I added
For example I wanna my output to be as the following
x=input('enter elments number' :) % which as an example =3
then
output = menu('Choose a element number','1 ','2 ','3')
I wanna do it automatically so if x=input('enter elments number' :) % which as an example =4
output = menu('Choose a element number','1 ','2 ','3','4')
Can anyone help ?
Thanks,
~

回答 (2 件)

Fangjun Jiang
Fangjun Jiang 2020 年 1 月 29 日
x=5;
xx=string(1:x);
menu('choose',xx(:))
  4 件のコメント
Ali Tawfik
Ali Tawfik 2020 年 1 月 29 日
Thanks again for your prompt relpy.
It's working now, I just have one more question, I would like to have specfic data for each selection in the menu but not working, could you help me
So I would like my have an output for each selection from the menu , is it possible,
Thanks,
Fangjun Jiang
Fangjun Jiang 2020 年 1 月 29 日
menu() returns the index number so you konw which button the user clicked. To get different data based on this input, you need to do it afterwards in your program.

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


Ali Tawfik
Ali Tawfik 2020 年 1 月 30 日
I think you misunderstood me, because I would like to add (for loop , or while )to add for each index a command then store them ?
Like the following
x=5;
xx=num2str([1:x]');
yy=mat2cell(xx,ones(x,1),1);
menu('choose',yy(:))
for menu(1)
f=2
menu(2)
f=3 and so on...
Hope you get what I want
  1 件のコメント
Fangjun Jiang
Fangjun Jiang 2020 年 1 月 30 日
編集済み: Fangjun Jiang 2020 年 1 月 30 日
What is "for menu(1)", "menu(2)"? There is no such syntax. I could only guess this is what you want.
f=[10, 200, 3000];
selection=menu('choose','1','2','3');
output=f(selection)

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

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by