This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materials including this page, select Japan from the country navigator on the bottom of this page.


Create question dialog box


button = questdlg('qstring')
button = questdlg(qstring,title)
button = questdlg(qstring,title,default)
button = questdlg(qstring,title,str1,str2,default)
button = questdlg(qstring,title,str1,str2,str3,default)
button = questdlg(qstring,title, ..., options)


button = questdlg('qstring') displays a modal dialog box presenting the question 'qstring'. The dialog has three default buttons, Yes, No, and Cancel. If the user presses one of these three buttons, button is set to the name of the button pressed. If the user presses the close button on the dialog without making a choice, button returns as an empty character vector (''). If the user presses the Return key, button returns with a value of 'Yes'. The 'qstring' argument is a character vector or cell array of character vectors that automatically wrap to fit within the dialog box.


A modal dialog box prevents the user from interacting with other windows before responding. For more information, see WindowStyle in the MATLAB® Figure Properties.

button = questdlg(qstring,title) displays a question dialog with title displayed in the dialog's title bar.

button = questdlg(qstring,title,default) specifies which push button is the default in the event that the Return key is pressed. default must be 'Yes', 'No', or 'Cancel'.

button = questdlg(qstring,title,str1,str2,default) creates a question dialog box with two push buttons labeled str1 and str2. default specifies the default button selection and must be str1 or str2.

button = questdlg(qstring,title,str1,str2,str3,default) creates a question dialog box with three push buttons labeled str1, str2, and str3. default specifies the default button selection and must be str1, str2, or str3.

When default is specified, but is not set to one of the button names, pressing the Enter key displays a warning and the dialog remains open.

button = questdlg(qstring,title, ..., options) replaces the default argument with a structure called options. The structure specifies which button is the default answer, and whether to use TeX to interpret the question text. Button labels and dialog titles cannot use the TeX interpreter. The options structure must include the fields Default and Interpreter. The structure can include other fields, but questdlg does not use them. You can set Interpreter to 'none' or 'tex'. If the Default field does not contain a valid button label, a command window warning is issued and the dialog box does not respond to pressing the Enter key.


Example 1

Create a dialog that requests a dessert preference and encode the resulting choice as an integer.

% Construct a questdlg with three options
choice = questdlg('Would you like a dessert?', ...
	'Dessert Menu', ...
	'Ice cream','Cake','No thank you','No thank you');
% Handle response
switch choice
    case 'Ice cream'
        disp([choice ' coming right up.'])
        dessert = 1;
    case 'Cake'
        disp([choice ' coming right up.'])
        dessert = 2;
    case 'No thank you'
        disp('I''ll bring you your check.')
        dessert = 0;

To access the return value assigned to dessert, save the example as a function, for example choosedessert, by inserting this line on top:

function dessert = choosedessert
You can generalize the function by defining a switch statement. As the example shows, case statements can contain white space (but are case-sensitive).

Example 2

Specify an options structure to use the TeX interpreter to format a question.

options.Interpreter = 'tex';
% Include the desired Default answer
options.Default = 'Don''t know';
% Use the TeX interpreter in the question
qstring = 'Is \Sigma(\alpha - \beta) < 0?';
choice = questdlg(qstring,'Boundary Condition',...
    'Yes','No','Don''t know',options)

Introduced before R2006a

Was this topic helpful?