send variables to menu

The menu function takes string input (text, options). Is there anyway to pass variables to the string. For example:
A = [red blue green] or A = 214
B = menu('You chose: A(1)', 'Y', 'N')
B = menu('You chose: {A}', 'Y', 'N')
Or do I have to do it the long way with fprintf and if statements?

1 个评论

The first input to menu() is just a string. So you can pass in any string that can you can compose from your variables. Why not do something like this:
A = 214
B = menu( sprintf('You choose %f', A(1)), 'Y', 'N')
A = {'red','green','blue'}
B = menu( sprintf('You choose %s', A{1}), 'Y', 'N')

请先登录,再进行评论。

回答(0 个)

类别

帮助中心File Exchange 中查找有关 Workspace Variables and MAT Files 的更多信息

标签

提问:

2013-10-22

评论:

2013-10-22

Community Treasure Hunt

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

Start Hunting!

Translated by