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. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

warndlg

Create warning dialog box

Syntax

f = warndlg(msg)
f = warndlg(msg,title)
f = warndlg(msg,title,opts)
f = warndlg

Description

f = warndlg(msg) creates a nonmodal warning dialog box with the specified message and returns the dialog box figure object f. The message text wraps to fit the dialog box. The dialog box title is Warning Dialog.

example

f = warndlg(msg,title) specifies a custom dialog box title.

example

f = warndlg(msg,title,opts) specifies the window style when opts is set to 'non-modal', 'modal', or 'replace'. It specifies the window style and an interpreter for the msg argument when opts is a structure array.

f = warndlg creates a warning dialog box with a default title and message, as follows.

  • Default title: Warning Dialog

  • Default message: This is the default warning.

Examples

collapse all

f = warndlg('Pressing ACCEPT clears memory','Warning');

Create a structure to specify a modal window style and the TeX interpreter. Then, create a warning dialog box specifying the opts structure as an input argument. The TeX interpreter reads the \color{blue} characters in the message text as an instruction to render the message text in blue.

opts = struct('WindowStyle','modal',... 
              'Interpreter','tex');
f = warndlg('\color{blue} Pressing ACCEPT clears memory',...
             'Memory Warning', opts);

Input Arguments

collapse all

Warning message, specified as a character vector, cell array of character vectors, or a string array.

  • If you specify the message as a character vector, then MATLAB® wraps the text to fit the dialog box.

  • If you specify the message a cell array, then MATLAB wraps the text after each cell array element. MATLAB wraps the text of long cell array elements to fit the dialog box.

Example: 'This command clears your workspace.'

Dialog box title, specified as a character vector or string scalar.

Example: 'Workspace Warning'

Dialog box settings specified as a window style or a structure. The structure specifies the window style and an interpreter for the msg argument.

To specify the window style only, set opts to one of the values in this table.

ValueDescription
'non-modal'

Create a warning dialog box that is nonmodal. This dialog box has no effect on other open dialog boxes.

'modal'

Specify a warning dialog box that is modal.

If other warning dialog boxes have the same title, then MATLAB modifies the most recently active one with the current specifications. MATLAB deletes all other open error, message, and warning dialog boxes with the same dialog box title as the most recently active warning dialog box. The affected dialog boxes can be modal or nonmodal.

Message and error dialog boxes are created with the msgbox, and errordlg functions, respectively.

'replace'

Specify a warning dialog box that is nonmodal.

If other warning dialog boxes have the same title, then MATLAB modifies the most recently active one with the current specifications. MATLAB deletes all other open error, message, or warning dialog boxes with the same title as the most recently active warning dialog box. The affected dialog boxes can be modal or nonmodal.

Message and error dialog boxes are created with the msgbox, and errordlg functions, respectively.

To specify the window style and an interpreter for the warning dialog box message, create an opts structure with the fields WindowStyle and Interpreter. This table shows valid values for the fields. The structure must include both fields.

Field

Values

WindowStyle

'non-modal','modal', or 'replace'.

Interpreter

'none' or 'tex'. If set to 'tex', hen MATLAB renders the message using the TeX interpreter.

Use TeX markup to add superscripts and subscripts, modify the font type and color, and include special characters in the message text.

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 property to 'tex', the supported modifiers are as follows.

ModifierDescriptionExample
^{ }Superscript'text^{superscript}'
_{ }Subscript'text_{subscript}'
\bfBold font'\bf text'
\itItalic font'\it text'
\slOblique font (usually the same as italic font)'\sl text'
\rmNormal font'\rm text'
\fontname{specifier}Font name — Replace specifier with the name of a font family. You can use this in combination with other modifiers.'\fontname{Courier} text'
\fontsize{specifier}Font size —Replace specifier with a numeric scalar value in point units.'\fontsize{15} text'
\color{specifier}Font color — Replace specifier 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 specifier with a three-element RGB triplet.'\color[rgb]{0,0.5,0.5} text'

This table lists the supported special characters with the Interpreter property set to 'tex'.

Character SequenceSymbolCharacter SequenceSymbolCharacter SequenceSymbol

\alpha

α

\upsilon

υ

\sim

~

\angle

\phi

\leq

\ast

*

\chi

χ

\infty

\beta

β

\psi

ψ

\clubsuit

\gamma

γ

\omega

ω

\diamondsuit

\delta

δ

\Gamma

Γ

\heartsuit

\epsilon

ϵ

\Delta

Δ

\spadesuit

\zeta

ζ

\Theta

Θ

\leftrightarrow

\eta

η

\Lambda

Λ

\leftarrow

\theta

θ

\Xi

Ξ

\Leftarrow

\vartheta

ϑ

\Pi

Π

\uparrow

\iota

ι

\Sigma

Σ

\rightarrow

\kappa

κ

\Upsilon

ϒ

\Rightarrow

\lambda

λ

\Phi

Φ

\downarrow

\mu

µ

\Psi

Ψ

\circ

º

\nu

ν

\Omega

Ω

\pm

±

\xi

ξ

\forall

\geq

\pi

π

\exists

\propto

\rho

ρ

\ni

\partial

\sigma

σ

\cong

\bullet

\varsigma

ς

\approx

\div

÷

\tau

τ

\Re

\neq

\equiv

\oplus

\aleph

\Im

\cup

\wp

\otimes

\subseteq

\oslash

\cap

\in

\supseteq

\supset

\lceil

\subset

\int

\cdot

·

\o

ο

\rfloor

\neg

¬

\nabla

\lfloor

\times

x

\ldots

...

\perp

\surd

\prime

´

\wedge

\varpi

ϖ

\0

\rceil

\rangle

\mid

|

\vee

\langle

\copyright

©

Example: opts = 'modal'

Example: opts.WindowStyle = 'non-modal'; opts.Interpreter = 'tex';

More About

collapse all

Modal Dialog Box

A modal dialog box prevents a user from interacting with other MATLAB windows before responding to the modal dialog box.

Nonmodal Dialog Box

A nonmodal dialog box enables a user to interact with other MATLAB windows before responding to the nonmodal dialog box. A nonmodal dialog box is also referred to as normal.

Tips

  • MATLAB program execution continues even when a modal Warning dialog box is active. To block program execution until the user closes the dialog box, use the uiwait function.

Introduced before R2006a