Create error dialog box - MATLAB errordlg (2024)

Create error dialog box

collapse all in page

Syntax

f = errordlg(msg)

f = errordlg(msg,title)

f = errordlg(msg,title,opts)

f = errordlg

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.

Examples

collapse all

Specify Message and Title for Error Dialog Box

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

Create error dialog box - MATLAB errordlg (1)

Interpret Message for Modal Error Dialog Box

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

Create error dialog box - MATLAB errordlg (2)

Input Arguments

collapse all

msgError message
'This is the default error.' (default) | character vector | cell array of character vectors | string array

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

titleDialog box title
'Error Dialog' (default) | character vector | string scalar

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

Example: 'Input Error'

optsDialog box settings
'non-modal' | 'modal' | 'replace' | structure array

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

  • Modaldialogs (created using errordlg, msgbox, or warndlg)replace any existing dialogs created with these functions that alsohave 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

See Also

dialog | helpdlg | msgbox | warndlg

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.

Create error dialog box - MATLAB errordlg (3)

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)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
  • 日本 (日本語)
  • 한국 (한국어)

Contact your local office

Create error dialog box - MATLAB errordlg (2024)
Top Articles
Latest Posts
Article information

Author: Kimberely Baumbach CPA

Last Updated:

Views: 6390

Rating: 4 / 5 (61 voted)

Reviews: 92% of readers found this page helpful

Author information

Name: Kimberely Baumbach CPA

Birthday: 1996-01-14

Address: 8381 Boyce Course, Imeldachester, ND 74681

Phone: +3571286597580

Job: Product Banking Analyst

Hobby: Cosplaying, Inline skating, Amateur radio, Baton twirling, Mountaineering, Flying, Archery

Introduction: My name is Kimberely Baumbach CPA, I am a gorgeous, bright, charming, encouraging, zealous, lively, good person who loves writing and wants to share my knowledge and understanding with you.