How use waitfor
or uiwait
in app designer of MATLAB? These funtions only work with figures (GUIDE) not app designer windows. How can I have same behavior in app designer? I'm waiting for closing second window before continuing codes of main window.
-
Your premise is not correct. Both `waitfor` and `uiwait` work with `uifigure` objects. – sco1 Aug 22 '16 at 13:35
-
@excaza. In a push button of main window I have `second_window;`. This code opens second window. After that `waitfor(second_window, 'close');` was used to wait for closing second window. Second function returns this error after running: `error using waitfor, invalid proporty`. – Eghbal Aug 22 '16 at 13:39
-
Thank you for comment. It worked without `close` but as you can see in `waitfor` documentation we can use `close` as an option in GUIDE. So there isn't any `close` property in app designer windows? – Eghbal Aug 22 '16 at 13:46
1 Answers
The waitfor(second_window, 'close');
is not actually waiting for the figure window to close. Specifying a second input to waitfor
tells MATLAB to block execution until the specified property changes or the object is deleted.
MATLAB autocompletes property names if there are enough characters to match a unique name*. In your case, 'close'
matches the figure's CloseRequestFcn
. UI figure objects do not have this property, hence the error.
Call waitfor
without the second input to achieve the desired behavior.
* I'm not sure if this is explicitly stated in MATLAB's documentation anywhere, but the functional equivalent is the PartialMatching
property of MATLAB's inputParser
class:
Inputs that are leading substrings of parameter names will be accepted and the value matched to that parameter. If there are multiple possible matches to the input string, MATLAB throws an error.

- 12,154
- 5
- 26
- 48