uiwait

Block program execution and wait to resume

Syntax

uiwait
uiwait(h)
uiwait(h,timeout)

Description

uiwait blocks execution until uiresume is called or the current figure is deleted. This syntax is the same as uiwait(gcf).

uiwait(h) blocks execution until uiresume is called or the figure h is deleted.

uiwait(h,timeout) blocks execution until uiresume is called, the figure h is deleted, or timeout seconds elapse. The minimum value of timeout is 1. If uiwait receives a smaller value, it issues a warning and uses a 1 second timeout.

Examples

This example creates a GUI with a Continue push button. The example calls uiwait to block MATLAB® execution until uiresume is called. This happens when the user clicks the Continue push button because the push button's Callback, which responds to the click, calls uiresume.

f = figure;
h = uicontrol('Position',[20 20 200 40],'String','Continue',...
              'Callback','uiresume(gcbf)');
disp('This will print immediately');
uiwait(gcf); 
disp('This will print after you click Continue');
close(f);

gcbf is the handle of the figure that contains the object whose callback is executing.

More About

expand all

Tips

The uiwait and uiresume functions block and resume MATLAB and Simulink® program execution. uiwait also blocks the execution of Simulink models. The functions pause (with no argument) and waitfor also block execution in this manner. uiwait is a convenient way to use the waitfor command. You typically use it in conjunction with a dialog box. It provides a way to block the execution of the MATLAB program that created the dialog, until the user responds to the dialog box. When used in conjunction with a modal dialog, uiwait can block the execution of the program file and restrict user interaction to the dialog only.

Was this topic helpful?