Documentation

menu

(Not recommended) Create multiple-choice dialog box

Note

Themenufunction is not recommended. Use thelistdlgfunction instead.

Syntax

choice = menu(message,opt1,opt2,...,optn)
choice = menu(message,options)

Description

choice = menu(message,opt1,opt2,...,optn)displays a modal menu dialog box containing the text inmessageand the choices specified byopt1,opt2,...optn. Themenufunction returns the number of the selected menu item, or 0 if the user clicks the close button on the window. Specifymessageas a character vector or string scalar. Specifyopt1,opt2,...optnas character vectors or string scalars.

choice = menu(message,options)specifies the choices as a cell array of character vectors or string array.

If the user's terminal provides a graphics capability,menudisplays 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).

Examples

Example 1

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

choice = menu('Choose a color','Red','Blue','Green')
displays the following dialog box.

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

After input is accepted, the dialog box closes, returning the output inchoice. You can usechoiceto control the color of a graph:

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

Example 2

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

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

displays the following text.

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

Tips

To callmenufrom within a callback of aUIControlor other UI component, set that object'sInterruptibleproperty to'on'. For more information, seeUIControl Properties.

Introduced before R2006a

Was this topic helpful?