Access .mlapp data in .m file after app closes

조회 수: 8 (최근 30일)
Jonathan Avesar
Jonathan Avesar 2020년 6월 5일
댓글: Tommy 2020년 6월 8일
Hello,
I have a script (.m) that calls a app (.mlapp) that I created using AppDesigner. The app is designed to collect user input. After the user enters the values, he/she clicks an OK button which propmpts the app to close. After the app closes, I want to access the user data from the app in the scipt (.m) and perform operations with the data. How do I do this?
I tried creating "public" properties and storing the values in the said created public properties, but I cant access those properties after the app is closed because the handle is deleted when the app deletes. I understand that it is possible to transfer data before the app deletes but the problem with that is that I don't know when the user is finished entering the data until the app is deleted.
My code in the script (.m) looks something like this:
H = myApp;
waitfor(H)
%Here I need to access the data from myApp

채택된 답변

Tommy
Tommy 2020년 6월 5일
Rather than waitfor(H), which waits until H is deleted, how about waitfor(H,propname,propvalue), where propname is some property of H that gets set to propvalue once the user is finished entering data? And delete your app after you've grabbed the relevant properties, rather than from within the app.
  댓글 수: 2
Jonathan Avesar
Jonathan Avesar 2020년 6월 8일
Hi Tommy,
Thank you so much, that method worked! I ended up creating a public variable within the app called
app.Finished = false; %Status of the app, True if user finished entering data
and set it to true when the user clicks on the OK button. I then added this structure in my script (.m) file:
%Wait for a positive finished state
waitfor(H,'Finished',true)
%Collect app data
attribute = H.attribute.Value;
%Close the app
delete(H)
And that worked perfectly!
**Hint, do not use a while loop in the main script. I tried that first before using this strategy and the main script was not capable of reading in new app attributes for exiting the loop while in the loop (e.g. while ~H.Finished)
Tommy
Tommy 2020년 6월 8일
Awesome! I am super glad that worked, this was a bit of a fun one. Happy to help as always!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기

태그

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by