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");
Message Dialog Box Text with Line Breaks
Specify the message dialog box text using a string array.
f = msgbox(["Operation";"Completed"]);
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");
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");
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);
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);
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);
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"));
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);
Input Arguments
collapse all
message
— Dialog 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"]
title
— Title
character vector | string scalar
Title, specified as a character vector or string scalar.
Example: "Success"
icon
— Icon
"none"
(default) | "help"
| "warn"
| "error"
| "custom"
Icon, specified as "help"
, "warn"
, or "error"
or "none"
.
This table lists the values and the corresponding icons.
Value | Icon |
---|---|
"help" | |
"warn" | |
"error" | |
"none" | No icon displays. |
icondata
— Image 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
iconcmap
— Colormap
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
createmode
— Window 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 specifiedtitle
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 specifiedtitle
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 fieldsWindowStyle
andInterpreter
. The value of theWindowStyle
field must be"non-modal"
,"modal"
, or"replace"
. The value of theInterpreter
field must be"tex"
or"none"
. If theInterpreter
value is"tex"
, MATLAB interprets the message value as TeX. The default value forInterpreter
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.
Modifier | Description | Example |
---|---|---|
^{ } | Superscript | 'text^{superscript}' |
_{ } | Subscript | 'text_{subscript}' |
\bf | Bold font | '\bf text' |
\it | Italic font | '\it text' |
\sl | Oblique font (usually the same as italic font) | '\sl text' |
\rm | Normal font | '\rm text' |
\fontname{ | Font name — Replace with the name of a font family. You can use this in combination with other modifiers. | '\fontname{Courier} text' |
\fontsize{ | Font size —Replace with a numeric scalar value in point units. | '\fontsize{15} text' |
\color{ | Font color — Replace 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 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 Sequence | Symbol | Character Sequence | Symbol | Character Sequence | Symbol |
---|---|---|---|---|---|
| α |
| υ |
| ~ |
| ∠ |
| ϕ |
| ≤ |
|
|
| χ |
| ∞ |
| β |
| ψ |
| ♣ |
| γ |
| ω |
| ♦ |
| δ |
| Γ |
| ♥ |
| ϵ |
| Δ |
| ♠ |
| ζ |
| Θ |
| ↔ |
| η |
| Λ |
| ← |
| θ |
| Ξ |
| ⇐ |
| ϑ |
| Π |
| ↑ |
| ι |
| Σ |
| → |
| κ |
| ϒ |
| ⇒ |
| λ |
| Φ |
| ↓ |
| µ |
| Ψ |
| º |
| ν |
| Ω |
| ± |
| ξ |
| ∀ |
| ≥ |
| π |
| ∃ |
| ∝ |
| ρ |
| ∍ |
| ∂ |
| σ |
| ≅ |
| • |
| ς |
| ≈ |
| ÷ |
| τ |
| ℜ |
| ≠ |
| ≡ |
| ⊕ |
| ℵ |
| ℑ |
| ∪ |
| ℘ |
| ⊗ |
| ⊆ |
| ∅ |
| ∩ |
| ∈ |
| ⊇ |
| ⊃ |
| ⌈ |
| ⊂ |
| ∫ |
| · |
| ο |
| ⌋ |
| ¬ |
| ∇ |
| ⌊ |
| x |
| ... |
| ⊥ |
| √ |
| ´ |
| ∧ |
| ϖ |
| ∅ |
| ⌉ |
| 〉 |
| | |
| ∨ |
| 〈 |
| © |
Output Arguments
collapse all
f
— Figure
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.
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)
Contact your local office