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.


Block program execution and wait to resume




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. The figure can be one that is created with figure or uifigure function. Only figures created with the figure function are returned by gcf.

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.


This example creates a UI 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',...
disp('This will print immediately');
disp('This will print after you click Continue');

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


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.

Introduced before R2006a