How to load variables from a workspace in App Designer?

19 次查看(过去 30 天)
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 个评论
Antonius Armanious
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?

请先登录,再进行评论。

采纳的回答

Chris Portal
Chris Portal 2017-3-8
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!

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Develop Apps Using App Designer 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by