waitfor

Wait for condition.

Syntax

  • waitfor(obj)

  • waitfor(obj, propertyName)

  • waitfor(obj, propertyName, propertyValue)

Input argument

  • obj - any scalar graphics object value.

  • propertyName - property name: character vector or string scalar.

  • propertyValue - property value: valid property value associated with propertyName.

Description

waitfor(obj) pauses the execution of statements until the specified object is closed (or deleted). Once the object is no longer present, waitfor returns, allowing the execution to continue. If the object does not exist at the time of the call, waitfor returns immediately.

waitfor(obj, propertyName) halts execution until the specified property of the object changes or the object is closed. For example, waitfor(hFig, 'UserData') pauses execution until the 'UserData' property of hFig changes. If the specified property name is invalid, an error stops execution.

waitfor(obj, propertyName, propertyValue) pauses execution until the specified property of the object changes to the given value. If the property is already equal to propvalue when waitfor is called, it returns immediately, allowing execution to resume.

Examples

h = figure()
waitfor(h);
% close figure to continue
hFig = figure('Position', [300, 300, 300, 150]);
hButton = uicontrol('Style', 'togglebutton', 'String', 'Toggle Me', 'Position', [100, 50, 100, 40], 'Value', 0);
hButton.Callback = @(src, event) set(src, 'Value', 1);
waitfor(hButton, 'Value');
% press toggle button
hFig = figure('Position', [300, 300, 300, 150]);
hButton = uicontrol('Style', 'togglebutton', 'String', 'Toggle Me', 'Position', [100, 50, 100, 40], 'Value', 0);
hButton.Callback = @(src, event) set(src, 'Value', 1);
waitfor(hButton, 'Value', 1);
% press toggle button

See also

figure, waitforbuttonpress, pause.

History

VersionDescription

1.7.0

initial version

Author

Allan CORNET

Last updated