waitfor
Block execution and wait for condition
Description
waitfor( blocks statements from executing
        until the specified object closes (is deleted). When the object no longer exists,
          obj)waitfor returns, enabling execution to resume. If the object does not
        exist, waitfor returns immediately.
waitfor(
        specifies a property name of the object and blocks execution until the value of the property
        changes or the object closes. For example, obj,propname)waitfor(mytable,'Data') pauses
        execution until the value of 'Data' changes for
          mytable. If the specified property name is invalid, execution remains
        blocked.
Examples
Input Arguments
Tips
If you close the figure while
waitforis executing, an error occurs because the code attempts to access objects that no longer exist. You can handle the error by enclosingwaitforin atry/catchblock.
Algorithms
Typically, callbacks can still run if waitfor has been used to
      prevent programs or Simulink® models from continuing execution. For example, callbacks that respond to user
      actions (like pressing a mouse button) can still run even if waitfor has
      been called.
waitfor can also be used to block nested function calls. For example,
      a callback that executes while the waitfor function is running can also
      call waitfor.
 If a callback function of a UI component is currently executing the
        waitfor function, then that callback can be interrupted regardless of
      what the Interruptible property value for that component has been set to. 
Version History
Introduced before R2006a