Appdesigner: Loading a MAT file - Difference between doing it from MATLAB vs from within Appdesigner.

2 vues (au cours des 30 derniers jours)
If I load a MAT file from the MATLAB prompt e.g. load('Default_Patient.mat') it will nicely add:-
'Default_Patient 'ZaphodBeeblebrox'
...to the MATLAB Base workspace.
But, if I use the same command from within Appdesigner (even in the Startup Fn) I get:
'Default_Patient 1 x 1 struct'
where 1 x 1 struct contains: 'Default_Patient 'ZaphodBeeblebrox'
1) I don't understand why there is a difference - when it is exactly the same command.
2) Is there a way of just adding the 'ZaphodBeeblebrox' part to the Base workspace (when doing this from Appdesigner) and loading from a MAT file ?
Thank you in anticipation of a kind and helpful answer.

Réponses (1)

Adam Danz
Adam Danz le 24 Fév 2020
1) I don't understand why there is a difference - when it is exactly the same command.
The load command loads the data into the caller's workspace. If the caller is the command window, the data will be loaded into the base workspace. If the caller is a function, the data will be loaded into the function's workspace.
2) Is there a way of just adding the 'ZaphodBeeblebrox' part to the Base workspace (when doing this from Appdesigner) and loading from a MAT file ?
You can load specific variables using this syntax: load(filename,variables) but I recommend using the output syntax in addition to that S = load(___).
You're requesting to load data into the base workspace from app designer but then the data wouldn't be accessible in App Designer without using risky methods. Instead, load the variables within the callback function and store them directly in your app.
The callback function would look something like this after you declare FileData as a property (see link above).
% Load the variables into a structure.
S = load(filename, {'Var1', 'Var2'});
app.FileData = S;
Then you can retreive the data anywhere in your app by using
app.FileData.Var1
  2 commentaires
Adam Danz
Adam Danz le 24 Fév 2020
Modifié(e) : Adam Danz le 27 Mar 2020
Glad I could help. Let me know if you stuck implementing those suggestions.

Connectez-vous pour commenter.

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