MATLAB Answers

Wait for app to close before continuing with script

22 views (last 30 days)
Frankie on 16 Nov 2020
Commented: Adam Danz on 17 Nov 2020
I'm a newb to using App Designer. I've built the GUI that works wonderfully, and can open it programmatically from my main .m script. However, I cannot for the life of me figure out how to force the .m script to wait for the App GUI to close. I figure it has something to do with assigning modality in App Designer. I've tried using a waitfor indexing with a variable written to my base workspace from the app to no avail. I've tried using a while condition, also to no avail. Are there any ways to make the main script wait for the app to close before continuing?


Sign in to comment.

Accepted Answer

Mario Malic
Mario Malic on 16 Nov 2020
Hello Frankie,
Here's an example how to do it.
app = NameOfApp;
while isvalid(app); pause(0.1); end


Frankie on 17 Nov 2020
Thank you so much - that worked perfectly. Kicking myself on how simple that was now!
Adam Danz
Adam Danz on 17 Nov 2020
also see waitfor
% [pre-app code]
app = myapp; % open app
waitfor(app) % wait for app to close
% [post-app code

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!