Products & Services Industries Academia Support User Community Company

Learn more about MATLAB   

menu - Generate menu of choices for user input

Syntax

choice = menu('mtitle','opt1','opt2',...,'optn')
choice = menu('mtitle',options)

displays the

Description

choice = menu('mtitle','opt1','opt2',...,'optn') menu whose title is in the string variable 'mtitle' and whose choices are string variables 'opt1', 'opt2', and so on. The menu opens in a modal dialog box. menu returns the number of the selected menu item, or 0 if the user clicks the close button on the window.

choice = menu('mtitle',options) , where options is a 1-by-N cell array of strings containing the menu choices.

If the user's terminal provides a graphics capability, menu displays the menu items as push buttons in a figure window (Example 1). Otherwise. they will be given as a numbered list in the Command Window (Example 2).

Remarks

To call menu from a uicontrol or other ui object, set that object's Interruptible property to 'on'. For more information, see Uicontrol Properties.

Examples

Example 1

On a system with a display, menu displays choices as buttons in a dialog box:

choice = menu('Choose a color','Red','Green','Blue') displays

The number entered by the user in response to the prompt is returned as choice (i.e., choice = 2 implies that the user selected Blue).

After input is accepted, the dialog box closes, returning the output in choice. You can use choice to control the color of a graph:

t = 0:.1:60;
s = sin(t);
color = ['r','g','b']
plot(t,s,color(choice))

Example 2

On a system without a display, menu displays choices in the Command Window:

choice = menu('Choose a color','Red','Blue','Green') 

displays the text

----- Choose a color -----
1) Red
2) Blue
3) Green
Select a menu number:

See Also

guide, input, uicontrol, uimenu

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS