Main Content

warndlg

Create warning dialog box

Description

Note

In App Designer and apps created with the uifigure function, uialert is recommended over warndlg because it provides additional customization options.

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.

Use the warndlg function if you want to show a warning dialog box over multiple app windows, the MATLAB® desktop, or Simulink® and still be able to interact with them before responding to the dialog box.

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');

Warning dialog box with title "Warning". The dialog box contains a yellow warning icon, the text "Pressing ACCEPT clears memory", and a button labeled "OK".

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

Warning dialog box with blue text

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 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 for the 'tex' interpreter.

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 dialog box.

Nonmodal Dialog Box

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

Tips

  • Modal dialogs (created using errordlg, msgbox, or warndlg) replace any existing dialogs created with these functions that also have the same name.

  • 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.

  • To create a modal alert dialog box for single-window App Designer or uifigure-based apps, use the uialert function instead.

Version History

Introduced before R2006a