uialert
Display alert dialog box
Description
uialert(
displays a modal dialog box in front of the specified figure window. The figure must
be created with the fig
,message
,title
)uifigure
function. The dialog box
displays the specified message and has a title bar with the specified title. By
default, the dialog box also contains an error icon and an OK
button.
uialert(___,
displays a dialog box with properties specified by one or more
Name,Value
)Name,Value
arguments.
Examples
Alert App User to Error
Create a modal alert dialog box. The figure behind it is inaccessible until you close the dialog box.
fig = uifigure; uialert(fig,"File not found.","Invalid File");
Create Multiline Modal Alert Dialog Box with Warning Icon
fig = uifigure; message = ["Fire hazard!","Consider reducing temperature."]; uialert(fig,message,"Warning", ... "Icon","warning");
Display Formatted MATLAB Error
Create a figure and two matrices of different sizes.
fig = uifigure; A = rand(3); B = ones(5);
Attempt to vertically concatenate the matrices. Handle any errors that
occur by getting the error text and creating an alert dialog box in the
figure, and then specify the error text as the dialog message. MATLAB® error text often includes HTML formatting, so specify the
dialog interpreter as 'html'
. The error is displayed with
a link to the documentation for the vertcat
function.
try C = vertcat(A,B); catch ME report = getReport(ME); uialert(fig,report,"Error Message","Interpreter","html"); end
Input Arguments
fig
— Target figure
Figure
object
Target figure, specified as a Figure
object. The figure
must be created with the uifigure
function.
message
— Message
character vector | cell array of character vectors | string array
Message, specified as a character vector, cell array of character vectors, or string array. The message can be any length.
To display multiple lines of text, use a cell array of character vectors or a string array, where each element in the array is a different line of text.
Example: 'Invalid value'
title
— Title
character vector | string scalar
Title, specified as a character vector or string scalar. Long titles truncate and are followed by ellipses. The exact length at which a title is truncated depends on your system setup.
Spaces replace format characters, such as the newline
(\n
) character.
Name-Value Arguments
Specify optional pairs of arguments as
Name1=Value1,...,NameN=ValueN
, where Name
is
the argument name and Value
is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Before R2021a, use commas to separate each name and value, and enclose
Name
in quotes.
Example: 'Icon','warning'
CloseFcn
— Alert dialog box close request function callback
''
(default) | function handle | cell array | character vector
The alert dialog box close request callback function, specified as one of these values:
Function handle.
Cell array in which the first element is a function handle. Subsequent elements in the cell array are the arguments to pass to the callback function.
Character vector that is a valid MATLAB expression. MATLAB evaluates this expression in the base workspace.
The CloseFcn
callback executes when the app user
dismisses the alert dialog box by clicking the close button in the title
bar or clicking the OK button. The
CloseFcn
function also executes when the app
user closes the figure window for which the alert dialog box displays
from the MATLAB command line. You can close a figure window from the
command line using the close
function.
Icon
— Icon
'error'
(default) | predefined icon | custom icon
Icon, specified as a predefined icon or a custom icon.
Predefined Icon
This table lists the values for the predefined icons. For example,
to show the check mark icon, specify the name-value pair
'Icon','success'
.
Value | Icon |
---|---|
'error' (default) |
|
'warning' |
|
'info' |
|
'question' |
|
'success' |
|
'' | No icon displays. |
Custom Icon
Specify a custom icon as one of these values:
A character vector that specifies the file name of an SVG, JPEG, GIF, or PNG image that is on the MATLAB path. Alternatively, you can specify a full path to the image file.
A truecolor image array. See Image Types for more information.
Modal
— Modal
true
(default) | false
Modal, specified as true
or
false
.
A modal dialog box is one that makes the figure inaccessible until the dialog box is closed. However, it does not prevent additional dialog boxes from appearing.
Interpreter
— Dialog text interpreter
'none'
(default) | 'tex'
| 'latex'
| 'html'
Dialog text interpreter, specified as:
'none'
— Display literal characters.'tex'
— Interpret text using a subset of TeX markup.'latex'
— Interpret text using a subset of LaTeX markup.'html'
— Interpret text using a subset of HTML markup.
TeX Markup
Use TeX markup to add superscripts and subscripts and to 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 |
| ... |
| ⊥ |
| √ |
| ´ |
| ∧ |
| ϖ |
| ∅ |
| ⌉ |
| 〉 |
| | |
| ∨ |
| 〈 |
| © |
LaTeX Markup
Use LaTeX markup to format and display mathematical expressions,
equations, and special characters. Use dollar symbols around the
marked up text. For example, use '$\int_1^{20} x^2
dx$'
for inline mode or '$$\int_1^{20} x^2
dx$$'
for display mode.
The displayed text uses the default LaTeX font style. You can use LaTeX markup to change the font style.
MATLAB supports most standard LaTeX math mode commands. For more information, see Supported LaTeX Commands.
HTML Markup
Use HTML markup to display links and customize font styles.
The interpreter supports a subset of HTML markup. As a general guideline, the interpreter supports text-related tags and styles. Unsupported tags and styles are ignored.
This table lists the supported elements and element attributes.
HTML Element | Attributes | Description |
---|---|---|
a | style , target , href , title | Hyperlink |
abbr | style , title | Abbreviation or acronym |
address | style | Contact information |
article | style | Self-contained, independent content |
aside | style | Content indirectly related to the main content |
b | style | Bold text |
bdi | style , dir | Content formatted in a different direction from surrounding text |
bdo | style , dir | Content formatted in a different direction from surrounding text |
big | style | Text one font size level larger than surrounding text (obsolete in HTML5) |
blockquote | style , cite | Extended quotation |
br | n/a | Line break |
caption | style | Caption or title of a table |
center | style | Content centered horizontally |
cite | style | Title of a creative work |
code | style | Fragment of code |
col | style , align , valign , span , width | Column within a table |
colgroup | style , align , valign , span , width | Group of columns within a table |
dd | style | Term or value in a description list |
del | style , datetime | Text that was deleted from a document |
details | style , open | Interactive widget with text visible only when toggled to 'open' state |
dl | style | Description list |
dt | style | Term or value in a description list |
em | style | Emphasized text (typically displayed in italic) |
font | style , color , size , face | Text with specified font properties (obsolete in HTML5) |
footer | style | Footer |
h1 . h2 , h3 , h4 , h5 , h6 | style | Section heading — <h1> is the highest level of heading and <h6> is the lowest |
header | style | Introductory content |
hr | style | Thematic break |
i | style | Text offset from the surrounding content — by default rendered as italic |
ins | style , datetime | Text inserted into a document |
li | style | Item in a list |
mark | style | Marked or highlighted text |
ol | style | Ordered list |
p | style | Paragraph |
pre | style | Preformatted text |
s | style | Text with a strikethrough |
strike | style | Text with a strikethrough (obsolete in HTML5) |
section | style | Standalone section |
small | style | Text one font size level smaller than surrounding text (obsolete in HTML5) |
sub | style | Subscript |
sup | style | Superscript |
strong | style | Text with strong importance |
table | style , width , border , align , valign | Table |
tbody | style , align , valign | Table body |
td | style , width , rowspan , colspan , align , valign | Table data cell |
tfoot | style , align , valign | Set of table rows that summarize the table columns |
th | style , width , rowspan , colspan , align , valign | Table data cell specified as a header of a group of cells |
thead | style , align , valign | Set of table rows that specify the column heads |
tr | style , rowspan , align , valign | Row of table cells |
tt | style | Monospace text (obsolete in HTML5) |
u | style | Text with an unarticulated annotation — by default rendered as an underline |
ul | style | Unordered list |
For more information about these elements, see https://developer.mozilla.org/en-US/docs/Web/HTML/Element.
To use HTML markup to create a hyperlink that runs MATLAB code, see Create Hyperlinks that Run Functions.
You can use HTML style attributes to format HTML content. A style attribute is a string of CSS attributes and their values.
These CSS attributes are supported:
background-color
border-bottom
border-bottom-color
border-bottom-left-radius
border-bottom-right-radius
border-bottom-style
border-bottom-width
border-left
border-left-color
border-left-style
border-left-width
border-radius
border-right
border-right-color
border-right-style
border-right-width
border-spacing
border-style
border-top
border-top-color
border-top-left-radius
border-top-right-radius
border-top-style
border-top-width
border-width
color
direction
font-family
font-size
font-style
font-weight
height
hidden
line-height
margin
margin-bottom
margin-left
margin-right
margin-top
max-height
max-width
min-height
min-width
overflow
overflow-wrap
overflow-x
overflow-y
padding
padding-bottom
padding-left
padding-right
padding-top
text-align
text-anchor
text-decoration
text-indent
text-overflow
text-shadow
text-transform
title
translate
white-space
width
For more information about these attributes, see https://developer.mozilla.org/en-US/docs/Web/CSS/Reference.
Version History
Introduced in R2016aR2021b: Style text and display equations
Use the Interpreter
name-value argument to enable markup in
the dialog box text. Specify the interpreter as 'html'
,
'latex'
, 'tex'
, or
'none'
.
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:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other bat365 country sites are not optimized for visits from your location.
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
- United Kingdom (English)