Documentation Center

  • Trial Software
  • Product Updates

questdlg

Create and open question dialog box

Syntax

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)

Description

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 is set to the empty string. If the user presses the Return key, button is set to 'Yes'. 'qstring' is a cell array or a string that automatically wraps to fit within the dialog box.

    Note   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 string default with a structure, options. The structure specifies which button string is the default answer, and whether to use TeX to interpret the question string, qstring. Button strings and dialog titles cannot use TeX interpretation. The options structure must include the fields Default and Interpreter, both strings. It 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 name, a command window warning is issued and the dialog box does not respond to pressing the Enter key.

Examples

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;
end

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 providing the cases as string or cell array calling arguments.

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';
% Create a TeX string for the question
qstring = 'Is \Sigma(\alpha - \beta) < 0?';
choice = questdlg(qstring,'Boundary Condition',...
    'Yes','No','Don''t know',options)

See Also

| | | | | | | | | |

Was this topic helpful?