Create question dialog box
If you are using App Designer or creating apps with the
uifigure
function, then use uiconfirm
instead. For more information, see GUIDE Migration Strategies.
creates a modal
dialog box that presents a question and returns the user's response --
answer
= questdlg(quest
)'Yes'
, 'No'
,
'Cancel'
, or ''
.
By default, the dialog box has three standard buttons, labeled Yes, No, and Cancel.
If the user clicks one of these buttons, then the
answer
value is the same as the label of the
pressed button.
If the user clicks the close button (X) on the dialog box title
bar or presses the Esc key, then the
answer
value is an empty character vector ('
').
If the user presses the Return key, then the
answer
value is the same as the label of the
default button selection. In this case,
'Yes'
.
customizes two of the standard buttons by labeling them with the values of
answer
= questdlg(quest
,dlgtitle
,btn1
,btn2
,defbtn
)btn1
and btn2
. The third standard
button is removed. The defbtn
value must match the value of
btn1
or btn2
.
If the user presses the keyboard Return key, and the
defbtn
value does not match one of the button labels,
then the dialog box remains open.
answer = questdlg('Would you like a dessert?', ... 'Dessert Menu', ... 'Ice cream','Cake','No thank you','No thank you'); % Handle response switch answer case 'Ice cream' disp([answer ' coming right up.']) dessert = 1; case 'Cake' disp([answer ' coming right up.']) dessert = 2; case 'No thank you' disp('I''ll bring you your check.') dessert = 0; end
To access the return value assigned to dessert
, save
the example as a function. For example, create function
choosedessert
by making this the first line of
code.
function dessert = choosedessert
opts.Interpreter = 'tex'; % Include the desired Default answer opts.Default = 'Don''t know'; % Use the TeX interpreter to format the question quest = 'Is \Sigma(\alpha - \beta) < 0?'; answer = questdlg(quest,'Boundary Condition',... 'Yes','No','Don''t know',opts)