| MATLAB Function Reference | ![]() |
uiwait
uiwait(h)
uiwait(h,timeout)
uiresume(h)
The uiwait and uiresume functions block and resume MATLAB program execution.
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.
uiresume(h) resumes the M-file execution that uiwait suspended.
When creating a dialog, you should have a uicontrol component with a callback that calls uiresume or a callback that destroys the dialog box. These are the only methods that resume program execution after the uiwait function blocks execution.
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 M-file that created the dialog, until the user responds to the dialog box. When used in conjunction with a modal dialog, uiwait/uiresume can block the execution of the M-file and restrict user interaction to the dialog only.
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 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.
Using a Modal Dialog to Confirm an Operation is a more complex example for a GUIDE GUI. See Icon Editor for an example for a programmatically created GUI.
uicontrol, uimenu, waitfor, figure, dialog
![]() | uiputfile | uisave | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |