Block program execution and wait to resume
uiwait blocks execution until the
function is called or the current figure (
gcf) is deleted.
uiwait function blocks MATLAB® and Simulink® program execution.
uiwait also blocks the execution of
uiwait( blocks execution until the
uiresume function is called or the figure
deleted. The figure can be one that is created with either 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.
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 a
CloseFcn callback for the dialog box that calls the
uiresume 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')
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.');
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
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');
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 the
close 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
f— Figure object
Figure object, specified as a
Figure object created with either
timeout— Timeout duration
Timeout duration, specified as a numeric value in seconds. Specify a number greater
than or equal to
A modal dialog box prevents a user from interacting with other MATLAB windows before responding to the dialog box.