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

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.

답변 (1개)

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

Glad I could help. Let me know if you stuck implementing those suggestions.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

질문:

2020년 2월 23일

편집:

2020년 3월 27일

Community Treasure Hunt

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

Start Hunting!

Translated by