uialert

Display alert dialog box

Description

example

uialert(fig,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.

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

fig = uifigure;
message = sprintf('Fire hazard! \n Consider reducing temperature.');
uialert(fig,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. To display multiple lines of text, use a cell array of character vectors or a string array.

Example: 'Invalid value'

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

Introduced in R2016a