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.

uialert

(App Designer) Display alert dialog box

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.

Syntax

uialert(f,message,title)
uialert(___,Name,Value)

Description

example

uialert(f,message,title) displays a modal dialog box in front of the specified figure window. The figure must be created with the 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.

example

uialert(___,Name,Value) displays a dialog box with properties specified by one or more Name,Value pair arguments.

Examples

collapse all

Create a modal alert dialog box. The figure behind it is inaccessible until you close the dialog box.

f = uifigure;
uialert(f,'File not found','Invalid File');

f = uifigure;
message = sprintf('Fire hazard! \n Consider reducing temperature.');
uialert(f,message,'Warning',...
'Icon','warning');

Input Arguments

collapse all

Target figure, specified as a Figure object. The figure must be created with the uifigure function.

Message, specified as a character vector, cell array of character vectors, or string array. The message can be any length.

Format characters such as the newline character (\n) are honored. Use a cell array of character vectors or a string array to display multiple lines of text.

Example: 'Invalid value'

Title, specified as a character vector or string scalar. Long titles are truncated and followed by ellipses. The exact length at which a title is truncated depends on your system setup.

Format characters, such as the newline (\n) character, 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 quotes. You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: 'Icon','warning'

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, 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'.

ValueIcon
'error' (default)

'warning'

'info'

'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, 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.

See Also

Functions

Introduced in R2016a