uiwait and uiresume in App designer to control main code and sub code

9 ビュー (過去 30 日間)
邱
2024 年 9 月 4 日
コメント済み: 2024 年 9 月 4 日
In my main code, i need run a new mlapp, but i don't want main code to continue until I return a data from "sub.mlapp", how can i achieve it? thanks!
run("sub.mlapp")
subdata1=getappdata(0,'subdata');
% stop below code until I push return button in sub.mlapp
app.Compresspr.Value=subdata1.data1(1);
app.Compresspr2.Value=subdata1.data1(2);

採用された回答

Shivam
Shivam 2024 年 9 月 4 日
Hi 邱,
I get that you have a script that you want to continue executing once you have gathered that data from the app getting executed in the background.
You can achieve the desired behaviour using uiwait and uiresume with the steps mentioned below:
  1. Use the uiwait function to pause the execution of the main script after the 'sub.mlapp' is launched.
  2. Create a button in the 'sub.mlapp' and in its callback function gather the necessary data and use uiresume function to continue the main script. E.g.
% In the callback of the created button
% Collect data to return
subdata.data1 = [app.SomeValue1, app.SomeValue2]; % Example data
% Store data in the base workspace or handle it as needed
setappdata(0, 'subdata', subdata);
% Resume execution of the main script
uiresume(app.UIFigure);
Please note that above provided example is just an illustration of the workaround you can follow. Ensure that the data you need is properly set in the 'sub.mlapp' before calling uiresume.
You can visit these documentation links to know more about uiresume and uiwait functions:
  1. https://www.mathworks.com/help/matlab/ref/uiresume.html
  2. https://www.mathworks.com/help/matlab/ref/uiwait.html
I hope it helps in achieving the desired behaviour.
  3 件のコメント
Shivam
Shivam 2024 年 9 月 4 日
As suggested in my previous response, you need to use app.UIFigure. You have wrongly used it as app.Main.
You can look at the attached sub.mlapp to get a better understanding.
邱
2024 年 9 月 4 日
Thanks for your help! I've solved my problem. ^ ^

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMaintain or Transition figure-Based Apps についてさらに検索

製品


リリース

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by