# msgbox

Create message dialog box

## 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

 NoteIn 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

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

f = msgbox("Operation Completed"); 

Specify the message dialog box text using a string array.

f = msgbox(["Operation";"Completed"]); 

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

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

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

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

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

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

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 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 a structure to specify that the user must click 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);

## Input Arguments

collapse all

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

Example: "Operation Completed"

Example: ["Operation";"Completed"]

Title, specified as a character vector or string scalar.

Example: "Success"

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

This table lists the values and the corresponding icons.

ValueIcon
"help"

"warn"

"error"

"none"No icon displays.

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

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

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

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

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.

## Version History

Introduced before R2006a