This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

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

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

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 and title.

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 cell array of character vectors.

f = msgbox({'Operation';'Completed'});

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

f = msgbox('Operation 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 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);

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 and title values 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 property 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 with the Interpreter property set to 'tex'.

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.

More About

collapse all

modal dialog box

A modal dialog box prevents a user from interacting with other windows before responding to the modal dialog box.

Tips

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

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

Introduced before R2006a