Main Content

errordlg

Create error dialog box

Description

Note

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

f = errordlg(msg) creates a nonmodal error dialog box with the specified error message and returns the dialog box Figure object f. The message text wraps to fit the dialog box.

Use the errordlg function if you want to show an error 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 = errordlg(msg,title) specifies a custom dialog box title.

example

f = errordlg(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 = errordlg creates an error dialog box with a default title and message as follows.

  • Default title: Error Dialog

  • Default message: This is the default error.

Examples

collapse all

f = errordlg('File not found','File Error');

Error dialog box. The dialog box title is "File Error". The content of the dialog box consists of an alert icon, the text "File not found", and a button labeled "OK".

Create a structure,opts, to specify a modal window style and the TeX interpreter. Then, create an error dialog box specifying the opts structure as an input argument. The TeX interpreter renders the ^2 characters in the message text as a superscript.

opts = struct('WindowStyle','modal',... 
              'Interpreter','tex');
f = errordlg('Try this equation instead: f(x) = x^2',...
             'Equation Error', opts);

Error dialog box. The dialog box title is "Equation Error". The content of the dialog box consists of an alert icon, the text "Try this equation instead:" followed by formatted equation text, and a button labeled "OK".

Input Arguments

collapse all

Error 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: 'Input must be a scalar value.'

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

Example: 'Input Error'

Dialog box settings specified as a window style only 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 an error dialog box that is nonmodal. This dialog box has no effect on other open dialog boxes.

'modal'

Specify an error dialog box that is modal.

If other error 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 error dialog box. The affected dialog boxes can be modal or nonmodal.

Message and warning dialog boxes are created with the msgbox, and warndlg functions, respectively.

'replace'

Specify an error dialog box that is nonmodal.

If other error 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 error dialog box. The affected dialog boxes can be modal or nonmodal.

Message and warning dialog boxes are created with the msgbox, and warndlg functions, respectively.

To specify the window style and an interpreter for the error 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', then 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 Error 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