MATLAB Answers

How to load variables from a workspace in App Designer?

46 views (last 30 days)
I am trying to make an app which will allow me to load variables from a workspace and then plot these variables or run whatever manipulations on them; I have done several trails, but I failed.
Here you are the very basic trail.
I use button linked to
uiopen('load')
to load a workspace which has a structure called QCM_FH; after loading the file, I have another button to plot two columns from a table in this structure.
plot(QCM_FH(19).File(1).Cell(1).Data.Time, QCM_FH(19).File(1).Cell(1).Data.deltaF_1);
when I click on the plot button, I get this error.
Undefined variable "QCM_FH" or class "QCM_FH".
if I use this form instead
plot(app.QCM_FH(19).File(1).Cell(1).Data.Time, app.QCM_FH(19).File(1).Cell(1).Data.deltaF_1);
I get...
No appropriate method, property, or field 'QCM_FH' for class 'OpenFIle'
I tried other tricks like adding the structure name as property to the app but nothing worked. Any tips?
  1 Comment
Antonius Armanious
Antonius Armanious on 7 Mar 2017
I found a way around it but I am not sure it is the smartest way and it is not very general.
I created a public app variable with the name QCM_FH and add this line after loading the file.
app.QCM_FH = QCM_FH;
Is there any smarter more direct ways to do this?

Sign in to comment.

Accepted Answer

Chris Portal
Chris Portal on 8 Mar 2017
It sounds like you are trying to share data between 2 different button callbacks - one that does the load, and the other that does the plotting. Here's what's happening...
When you call UIOPEN, the data is getting loaded into the first button's callback workspace. The data is only visible to that callback, and when the callback exits, the data is getting cleared. In order to use the data in another callback, you have to cache the data somewhere that you can access later.
In the GUIDE world, you would normally cache the data in the handles structure or in some component's UserData property. In the App Designer world, the idea is the same, but the recommended place to cache it is in an app variable, exactly as you are doing.
Hope this helps!

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by