How to load variables from a workspace in App Designer?

20 vues (au cours des 30 derniers jours)
Antonius Armanious
Antonius Armanious le 7 Mar 2017
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 commentaire
Antonius Armanious
Antonius Armanious le 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?

Connectez-vous pour commenter.

Réponse acceptée

Chris Portal
Chris Portal le 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!

Plus de réponses (0)

Catégories

En savoir plus sur Develop Apps Using App Designer dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by