create menu with input
显示 更早的评论
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
2020-1-29
x=5;
xx=string(1:x);
menu('choose',xx(:))
4 个评论
Ali Tawfik
2020-1-29
Fangjun Jiang
2020-1-29
编辑:Fangjun Jiang
2020-1-29
this seems to work in R2016b
x=5;
xx=num2str([1:x]');
yy=mat2cell(xx,ones(x,1),1);
menu('choose',yy(:))
Ali Tawfik
2020-1-29
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
2020-1-30
0 个投票
1 个评论
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)
类别
在 帮助中心 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!