(Not recommended) Create multiple-choice dialog box
menu is not recommended. Use
Create a multiple choice dialog box with four options.
msg = "Choose your favorite animal"; opts = ["Dog" "Cat" "Horse" "Snake"]; choice = menu(msg,opts);
Select the second option and display the choice in the Command Window.
disp("You chose " + opts(choice))
You chose Cat
Create a multiple choice dialog box that prompts the user to choose a plot color.
choice = menu("Choose a color","Red","Blue","Green")
Select Green. Because this is the third menu option, the
choice = 3
Store the color options as a vector, and extract the selected color using the value
choice as the index. Plot some data using the selected plot
colors = ["r" "b" "g"]; plotcolor = colors(choice); t = 0:.1:60; s = sin(t); plot(t,s,plotcolor)
message— Dialog box text
Dialog box text, specified as a character vector or a string scalar.
options— Dialog box options
Dialog box options, specified as a cell array of character vectors or a string array. Each array element corresponds to a separate button.
opt— Dialog box option
Dialog box option, specified as a character vector or a string scalar.
choice— Dialog box selection
Dialog box selection, returned as a nonnegative integer. When the user selects a
button, the function returns the index of that button. For example, if you specify the
menu options as
["Red" "Blue" "Green"] and the user selects
Blue, the function returns
If the user closes the dialog box before selecting an option, the function returns
A modal dialog box prevents a user from interacting with other MATLAB® windows before responding to the dialog box.
menu from within a callback of a
UIControl or other UI component, set that object's
Interruptible property to
"on". For more
information, see UIControl Properties.
On a terminal that does not provide a graphics capability,
displays the options as a numbered list in the Command Window.