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

1 view (last 30 days)
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.

Answers (1)

Adam Danz
Adam Danz on 24 Feb 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

Categories

Find more on Downloads in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!