Create question dialog box
collapse all in page
Syntax
answer = questdlg(quest)
answer = questdlg(quest,dlgtitle)
answer = questdlg(quest,dlgtitle,defbtn)
answer = questdlg(quest,dlgtitle,btn1,btn2,defbtn)
answer = questdlg(quest,dlgtitle,btn1,btn2,btn3,defbtn)
answer = questdlg(quest,dlgtitle,opts)
answer = questdlg(quest,dlgtitle,btn1,btn2,opts)
answer = questdlg(quest,dlgtitle,btn1,btn2,btn3,opts)
Description
Note
In App Designer and apps created with the uifigure
function, uiconfirm is recommended over questdlg
because it provides additional customization options.
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'
.
specifies a dialog box title. answer
= questdlg(quest,dlgtitle)
specifies which button is the default if the user presses the keyboard Return key. The answer
= questdlg(quest,dlgtitle,defbtn)defbtn
value must match one of the button labels.
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.
example
customizes the third standard button with a label that matches the value of answer
= questdlg(quest,dlgtitle,btn1,btn2,btn3,defbtn)btn3
.
specifies an options structure to specify the default button selection and whether to use TeX to interpret the question text.answer
= questdlg(quest,dlgtitle,opts)
customizes two standard buttons with labels that match the values of answer
= questdlg(quest,dlgtitle,btn1,btn2,opts)btn1
and btn2
. The third standard button is removed.
example
customizes the third standard button with a label that matches the value of answer
= questdlg(quest,dlgtitle,btn1,btn2,btn3,opts)btn3
.
Examples
collapse all
Encode User's Choice as an Integer in Question Dialog Box
Create a question dialog box with three custom buttons. Assign a different value to the dessert
variable depending on the button the user clicks.
answer = questdlg('Would you like a dessert?', ...'Dessert Menu', ...'Ice cream','Cake','No thank you','No thank you');% Handle responseswitch 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
Format Question in Dialog Box Using TeX
opts.Interpreter = 'tex';% Include the desired Default answeropts.Default = 'Don''t know';% Use the TeX interpreter to format the questionquest = 'Is \Sigma(\alpha - \beta) < 0?';answer = questdlg(quest,'Boundary Condition',... 'Yes','No','Don''t know',opts)
Input Arguments
collapse all
quest
— Dialog box question
character vector | cell array of character vectors | string array
Dialog box question, specified as a character vector, cell array of character vectors, or string array. The question automatically wraps to fit within the dialog box.
Example: 'What is the velocity?'
dlgtitle
— Dialog box title
' ' (default) | character vector | string scalar
Dialog box title, specified as a character vector or string scalar.
Example: 'Configuration'
defbtn
— Default button selection
character vector | string scalar
The default button selection, specified as a character vector or string scalar. The default button selection is the value that MATLAB® returns if the user presses the keyboard Return key instead of clicking a button in the dialog box. The default selection must be the same as one of the dialog box button labels. If the defbtn
argument value does not match a button label, then the dialog box remains open if the user presses the keyboard Enter key.
Example: 'Cancel'
btn1
— First customized button label
character vector | string scalar
First customized button label, specified as a character vector or string scalar.
Example: 'Start'
btn2
— Second customized button label
character vector | string scalar
Second customized button label, specified as a character vector or string scalar.
Example: 'Reset'
btn3
— Third customized button label
character vector | string scalar
Third customized button label, specified as a character vector or string scalar.
Example: 'Test'
opts
— Dialog box settings
structure
Dialog box settings specified as a structure. The structure specifies which button is the default button selection, and whether to use TeX to interpret the question text.
The opts
structure, must include both of the fields presented in this table. The structure can include additional fields, but questdlg
does not use them.
Field | Values |
---|---|
| The default button selection, specified as a character vector or string scalar. The default selection must be the same as one of the dialog box button labels. The default button is the button value that MATLAB returns if the user presses the keyboard Return key instead of clicking a dialog box button. If the |
|
Use TeX markup to add superscripts and subscripts, modify the font type and color, and include special characters in the |
Modifiers remain in effect until the end of the text. Superscripts and subscripts are an exception because they modify only the next character or the characters within the curly braces. When you set the interpreter to 'tex'
, the supported modifiers are as follows.
Modifier | Description | Example |
---|---|---|
^{ } | Superscript | 'text^{superscript}' |
_{ } | Subscript | 'text_{subscript}' |
\bf | Bold font | '\bf text' |
\it | Italic font | '\it text' |
\sl | Oblique font (usually the same as italic font) | '\sl text' |
\rm | Normal font | '\rm text' |
\fontname{ | Font name — Replace with the name of a font family. You can use this in combination with other modifiers. | '\fontname{Courier} text' |
\fontsize{ | Font size —Replace with a numeric scalar value in point units. | '\fontsize{15} text' |
\color{ | Font color — Replace with one of these colors: red , green , yellow , magenta , blue , black , white , gray , darkGreen , orange , or lightBlue . | '\color{magenta} text' |
\color[rgb]{specifier} | Custom font color — Replace with a three-element RGB triplet. | '\color[rgb]{0,0.5,0.5} text' |
This table lists the supported special characters for the 'tex'
interpreter.
Character Sequence | Symbol | Character Sequence | Symbol | Character Sequence | Symbol |
---|---|---|---|---|---|
| α |
| υ |
| ~ |
| ∠ |
| ϕ |
| ≤ |
|
|
| χ |
| ∞ |
| β |
| ψ |
| ♣ |
| γ |
| ω |
| ♦ |
| δ |
| Γ |
| ♥ |
| ϵ |
| Δ |
| ♠ |
| ζ |
| Θ |
| ↔ |
| η |
| Λ |
| ← |
| θ |
| Ξ |
| ⇐ |
| ϑ |
| Π |
| ↑ |
| ι |
| Σ |
| → |
| κ |
| ϒ |
| ⇒ |
| λ |
| Φ |
| ↓ |
| µ |
| Ψ |
| º |
| ν |
| Ω |
| ± |
| ξ |
| ∀ |
| ≥ |
| π |
| ∃ |
| ∝ |
| ρ |
| ∍ |
| ∂ |
| σ |
| ≅ |
| • |
| ς |
| ≈ |
| ÷ |
| τ |
| ℜ |
| ≠ |
| ≡ |
| ⊕ |
| ℵ |
| ℑ |
| ∪ |
| ℘ |
| ⊗ |
| ⊆ |
| ∅ |
| ∩ |
| ∈ |
| ⊇ |
| ⊃ |
| ⌈ |
| ⊂ |
| ∫ |
| · |
| ο |
| ⌋ |
| ¬ |
| ∇ |
| ⌊ |
| x |
| ... |
| ⊥ |
| √ |
| ´ |
| ∧ |
| ϖ |
| ∅ |
| ⌉ |
| 〉 |
| | |
| ∨ |
| 〈 |
| © |
Example: opts.Default = 'Cancel'
Example: opts.Interpreter = 'tex'
More About
collapse all
Modal Dialog Box
A modal dialog box prevents the user from interacting with other MATLAB windows before responding.
Version History
Introduced before R2006a
See Also
inputdlg | listdlg
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- Deutsch
- English
- Français
- United Kingdom (English)
Contact your local office