uiwait - Block program execution and wait to resume - MATLAB (original) (raw)
Block program execution and wait to resume
Syntax
Description
uiwait
blocks execution until the uiresume
function is called or the current figure (gcf) is deleted.
The uiwait
function blocks MATLAB® and Simulink® program execution. uiwait
also blocks the execution of Simulink models.
uiwait([f](#mw%5Fb7f9d071-0fc4-44c0-aeb4-a8b15dbd911e))
blocks execution until theuiresume
function is called or the figure f
is deleted. The figure can be one that is created with either the figure
or uifigure
function.
Use the uiwait
function with a modal dialog box to block program execution and restrict user interaction to only the dialog box until the user responds to it.
uiwait([f](#mw%5Fb7f9d071-0fc4-44c0-aeb4-a8b15dbd911e),[timeout](#mw%5Ff9413640-a87a-462a-b22d-fb71c2da6477))
blocks execution until uiresume
is called, the figure is deleted, ortimeout
seconds elapse.
Examples
Wait for Response to Alert Dialog Box
Create an alert dialog box and wait for the user to respond to it before allowing program execution to continue.
Create a line plot in a UI figure and display an alert dialog box. Specify aCloseFcn
callback for the dialog box that calls theuiresume
function when the user responds to it. Wait for the user to click OK in the dialog box or close it. When program execution resumes, display a message in the Command Window.
fig = uifigure; fig.Position = [500 500 500 350]; ax = uiaxes(fig); plot(ax,1:10)
uialert(fig,'A line plot was created in the axes.', ... 'Program Information','Icon','info','CloseFcn','uiresume(fig)')
uiwait(fig) disp('Program execution resumed')
Wait for Response to Modal Message Dialog Box
Block program execution from continuing until the user responds to a modal message dialog box.
Create a line plot in a figure and display a modal message dialog box. Wait for the dialog box to be deleted when the user clicks OK or closes it. When program execution resumes, display a message in the Command Window.
f = figure; plot(1:10) msgfig = msgbox('Operation was completed successfully!','Success','modal'); uiwait(msgfig) disp('Program execution resumed.');
Wait for Button Press
Create a Continue button and wait until the user presses it. Then display a message.
Create a push button with a callback that calls the uiresume
function when it is clicked. Wait for the user to click Continue or close the figure window. Then display a message.
f = figure('Position',[500 500 400 300]); c = uicontrol('String','Continue','Callback','uiresume(f)'); uiwait(f) disp('Program execution has resumed');
Wait for Timeout
Create a figure that closes after a specified time.
Create a line plot in a UI figure.
fig = uifigure; fig.Position = [500 500 500 350]; ax = uiaxes(fig); plot(ax,1:10);
Create a five-second timeout. Then, close the figure by calling theclose
function from within a try
block. If it has already been closed, the catch
block prevents the error,Invalid figure handle
, from displaying and allows the code to continue executing normally.
uiwait(fig,5)
try close(fig) catch end
Input Arguments
f
— Figure object
Figure
object
Figure object, specified as a Figure
object created with either the figure
or uifigure
function.
timeout
— Timeout duration
numeric value
Timeout duration, specified as a numeric value in seconds. Specify a number greater than or equal to 1
.
More About
Modal Dialog Box
A modal dialog box prevents a user from interacting with other MATLAB windows before responding to the dialog box.
Version History
Introduced before R2006a