Wait for app to close before continuing with script

Hi,
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?

 採用された回答

Mario Malic
Mario Malic 2020 年 11 月 16 日

6 投票

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

8 件のコメント

Fernando
Fernando 2020 年 11 月 17 日
Thank you so much - that worked perfectly. Kicking myself on how simple that was now!
Adam Danz
Adam Danz 2020 年 11 月 17 日
+1
also see waitfor
% [pre-app code]
app = myapp; % open app
waitfor(app) % wait for app to close
% [post-app code
Rauf Iftikhar
Rauf Iftikhar 2021 年 6 月 17 日
編集済み: Rauf Iftikhar 2021 年 6 月 17 日
What if i have inputs and outputs for the app? My code is essentially this:
[x,y] = DGUI(x, y, d); %%code i need to run
[x,y] = waitfor(DGUI(x,y,d)); %error in waitfor --> too many output arguments
Thanks
Mario Malic
Mario Malic 2021 年 6 月 17 日
Does this even work? Asking because I am not sure if app supports input arguments or if DGUI is name of the app or function.
[x,y] = DGUI(x, y, d); %%code i need to run
Rauf Iftikhar
Rauf Iftikhar 2021 年 6 月 17 日
Has worked from the command line but not fully when run from the script. As I understand GUI's have varargin parameter and varargout output and thus can have multiple inputs/outputs.
Mario Malic
Mario Malic 2021 年 6 月 17 日
Does the figure close when this line is executed? You're talking about app made in GUIDE?
[x,y] = DGUI(x, y, d)
Rauf Iftikhar
Rauf Iftikhar 2021 年 6 月 17 日
no the figure opens at that command and closes on the CloseRequestFcn
Mario Malic
Mario Malic 2021 年 6 月 17 日
If it's made by guide and can be detected by gca, you can try with the code below, otherwise, see step 2 of this answer
fig = gca;
if isvalid(fig)
waitfor(fig);
end
You can try removing CloseRequestFcn, write a public function so you could close it in your script.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeSignal Integrity Kits for Industry Standards についてさらに検索

質問済み:

2020 年 11 月 16 日

コメント済み:

2021 年 6 月 17 日

Community Treasure Hunt

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

Start Hunting!

Translated by