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. Please click here
To view all translated materials including this page, select Japan from the country navigator on the bottom of this page.


(App Designer) Display alert dialog box for UI figure window

Use only with App Designer or figures created with the uifigure function. When using GUIDE or the figure function, create alert dialog boxes using errordlg,warndlg, or msgbox.


uialert(figure, message, title)



uialert(figure, message, title) displays a modal dialog box in front of the specified UI figure window. 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(___,Name,Value) displays a dialog box with properties specified by one or more Name,Value pair arguments.


collapse all

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

fig = uifigure;
message = sprintf('Fire hazard! \n Consider reducing temperature.');

Input Arguments

collapse all

Figure window on which alert dialog box will display, specified as a Figure object returned by the uifigure function.

The text to display in the alert dialog box, specified as a character vector or a cell array of character vectors. The message can be any length.

If you specify the message as preformatted character vector using the sprintf function, format characters such as the newline character, \n, are honored. For instance, you can use sprintf('first line \n second line'). A cell array of character vectors is displayed as multiline text, where each row of the array is one line of text.

Example: 'Invalid value'

The text to display at the top of the alert dialog box, specified as a character vector. Long titles are truncated and followed by ellipses. The exact length at which a title is truncated depends on your system setup.

If you specify a preformatted character array using sprintf, then format characters, such as the newline (\n) character and the carriage return character (\r) , are replaced by spaces.

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: 'Icon','warning'

collapse all

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.

The icon for the alert dialog box, specified as one of the values listed in this table.


Icon is .


Icon is .


Icon is .


Icon is .


No icon included in the alert dialog box.

Path to a SVG, JPEG, GIF, or PNG image file

Icon is the image at the specified path. Vector format files (SVG images) automatically scale to fit the dialog box best. SVG files are the preferred format to support different resolution systems (for example, high-DPI systems).

Raster image formats are displayed in their actual size up to 32 by 32 pixels. Icons that are larger than 32 by 32 pixels are scaled down. Smaller icons are displayed as-is, without scaling up.

m-by-n-by-3 RGB image Cdata matrix

The CData format must be a 3-D array of truecolor RGB triplets. These values can be double-precision values between 0.0 and 1.0 or uint8 values between 0 and 255.

For more information on CData, see Image Properties in the MATLAB Graphics documentation.

An image file name must refer to a file that is discoverable by and accepted by the MATLAB which function. For example, the image file name must specify a name and extension of the image file on the MATLAB path or the full path to the image file.

Alert dialog box modal state with respect to the specified UI figure, specified as 'true', 'false', 1, or 0.

A modal alert dialog box is one that makes the figure inaccessible until the alert dialog box is closed. However, it does not prevent additional dialog boxes from appearing.

See Also


Introduced in R2016a

Was this topic helpful?