Create message dialog box - MATLAB msgbox (2024)

Create message dialog box

collapse all in page

Syntax

f = msgbox(message)

f = msgbox(message,title)

f = msgbox(message,title,icon)

f = msgbox(message,title,"custom",icondata,iconcmap)

f = msgbox(___,createmode)

Description

example

Note

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

f = msgbox(message) creates a message dialog box that automatically wraps message to fit an appropriately sized figure.

Use this function if you want to show a message 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 = msgbox(message,title) specifies the title of the message box.

example

f = msgbox(message,title,icon) specifies a predefined icon to display in the message dialog box.

example

f = msgbox(message,title,"custom",icondata,iconcmap) specifies a custom icon to include in the message dialog box. icondata is the image data that defines the icon. iconcmap is the colormap used for the image. If icondata is a truecolor image array, you do not need to specify iconcmap.

example

f = msgbox(___,createmode) specifies the window mode for the dialog box. Alternatively, you can specify a structure array that specifies the window mode and the interpreter for the message.

Examples

collapse all

Simple Message Dialog Box

Specify the text you want displayed in the message dialog box.

f = msgbox("Operation Completed");

Create message dialog box - MATLAB msgbox (1)

Message Dialog Box Text with Line Breaks

Message Dialog Box with a Title

Specify the message dialog box text and give the dialog box a title, Success.

f = msgbox("The operation has been successfully completed","Success");

Create message dialog box - MATLAB msgbox (3)

Message Dialog Box That Uses a Built-in Icon

Include a built-in error icon with an error message in a message dialog box entitled Error.

f = msgbox("Invalid Value","Error","error");

Create message dialog box - MATLAB msgbox (4)

Message Dialog Box That Uses a Truecolor Custom Icon

Read an RGB image into the workspace. Then, specify it as a custom icon in the dialog box.

myicon = imread("landOcean.jpg");h = msgbox("Operation Completed","Success","custom",myicon);

Create message dialog box - MATLAB msgbox (5)

Message Dialog Box That Uses an Indexed Color Icon

Read the image data and colormap into the workspace.

[icondata,iconcmap] = imread("trees.tif"); 

Create the message dialog box, including the custom icon.

h = msgbox("Operation Completed", ... "Success","custom",icondata,iconcmap);

Create message dialog box - MATLAB msgbox (6)

Adjust the image colors by specifying a different colormap. For instance, specify the MATLAB built-in colormap, summer.

h = msgbox("Operation Completed","Success","custom", ... icondata,summer);

Create message dialog box - MATLAB msgbox (7)

Modal Message Dialog Box

Create a modal message dialog box, wrapping the call to msgbox with uiwait to make the message dialog box block MATLAB execution until the user responds to the message dialog box.

uiwait(msgbox("Operation Completed","Success","modal"));

Create message dialog box - MATLAB msgbox (8)

Modal Message Dialog Box That Uses a TeX Formatted Message

Create a structure to specify that the user must click OK before interacting with another window and that MATLAB interpret the message text as TeX format.

CreateStruct.Interpreter = 'tex';CreateStruct.WindowStyle = 'modal';

Create the message dialog box.

h = msgbox("Z = X^2 + Y^2","Value",CreateStruct);

Create message dialog box - MATLAB msgbox (9)

Input Arguments

collapse all

messageDialog box text
character vector | cell array of character vectors | string array

Dialog box text, specified as a character vector, cell array of character vectors, or string array.

Example: "Operation Completed"

Example: ["Operation";"Completed"]

titleTitle
character vector | string scalar

Title, specified as a character vector or string scalar.

Example: "Success"

iconIcon
"none" (default) | "help" | "warn" | "error" | "custom"

Icon, specified as "help", "warn", or "error" or "none".

This table lists the values and the corresponding icons.

ValueIcon
"help"

Create message dialog box - MATLAB msgbox (10)

"warn"

Create message dialog box - MATLAB msgbox (11)

"error"

Create message dialog box - MATLAB msgbox (12)

"none"No icon displays.

icondataImage array
m-by-n array | m-by-n-by-3 truecolor image array

Image array, specified as an m-by-n array or an m-by-n-by-3 truecolor image array. You can also use imread to get the image array from a file.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

iconcmapColormap
three-column matrix of RGB triplets

Colormap, specified as a three-column matrix of RGB triplets. An RGB triplet is a three-element row vector whose elements specify the intensities of the red, green, and blue components of a color. The intensities must be in the range [0, 1].

Data Types: single | double

createmodeWindow mode
"non-modal" (default) | "modal" | "replace" | structure array

Window mode, specified as "non-modal", "modal", "replace", or a structure array.

  • If createmode is "non-modal", MATLAB creates a new nonmodal message box with the specified parameters. Existing message boxes with the same title remain.

  • If createmode is "modal", MATLAB replaces the existing message box with the specified title that was last created or clicked on with the specified modal dialog box. MATLAB deletes all other message boxes with the same title. The replaced message box can be either modal or nonmodal.

  • If createmode is "replace", MATLAB replaces the message box having the specified title that was last created or clicked on with a nonmodal message box as specified. MATLAB deletes all other message boxes with the same title. The replaced message box can be either modal or nonmodal.

  • If createmode is a structure array, it must have the fields WindowStyle and Interpreter. The value of the WindowStyle field must be "non-modal", "modal", or "replace". The value of the Interpreter field must be "tex" or "none". If the Interpreter value is "tex", MATLAB interprets the message value as TeX. The default value for Interpreter is "none".

TeX Markup

By default, MATLAB supports a subset of TeX markup. Use TeX markup to add superscripts and subscripts, modify the font type and color, and include special characters in the 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

©

Output Arguments

collapse all

fFigure object
Figure object

Figure object for the dialog box. Use f to query and modify the properties of the dialog box.

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.

  • Program execution continues even when a modal dialog box is active. To block MATLAB program execution until the user responds to the modal 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

uialert | errordlg | helpdlg | 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 message dialog box - MATLAB msgbox (13)

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 message dialog box - MATLAB msgbox (2024)
Top Articles
Latest Posts
Article information

Author: Maia Crooks Jr

Last Updated:

Views: 6354

Rating: 4.2 / 5 (43 voted)

Reviews: 90% of readers found this page helpful

Author information

Name: Maia Crooks Jr

Birthday: 1997-09-21

Address: 93119 Joseph Street, Peggyfurt, NC 11582

Phone: +2983088926881

Job: Principal Design Liaison

Hobby: Web surfing, Skiing, role-playing games, Sketching, Polo, Sewing, Genealogy

Introduction: My name is Maia Crooks Jr, I am a homely, joyous, shiny, successful, hilarious, thoughtful, joyous person who loves writing and wants to share my knowledge and understanding with you.