How to decompose Structure into its constituent variables from GUI?

I am developing a GUI using GUIDE. It has one pushbutton which selects .mat file which corresponds to base workspace variables stored from previous sessions.
However, when I load selected .mat file, it creates a structure variable in base workspace and that structure variable has all constituent variables of the original .mat file.
Can I decompose the structure variable in the callback of the pushbutton? so that after loading .mat file, base workspace will directly have all variables loaded instead of a single structure?

Answers (1)

If you saved the variables as individual variables and you just load them as:
load( 'someFile.mat' )
then you will get all the variables back anyway, not within a struct. This is not always advisable usage, but that is a different matter. Only using
s = load( 'someFile.mat' )
or if you saved them into a struct in the first place will you get a struct.
They won't be dropping into the base workspace though, they will appear in your pushbutton callback workspace when you load them.
Other than that though there are advantages to having variables in the struct format rather than loads of them being poofed into a workspace that you then have to refer to in a hard-coded fashion.

3 Comments

hi, yes I am using s=load('somefile.mat'); and passing the s into base workspace. Can I decompose s into its variables in callback function and then pass them into the base workspace?if yes, what is the best way to do it?
Just don't put the s= bit at the front.
I don't know why you would want variables in the base workspace though if you are working with a GUI. If you are working in the base workspace anyway then a GUI seems a waste - you can just load the file in directly on command line.
You ought to be able to do whatever you wanted to do in the base workspace in the callback workspace instead.
Hi Adam, I agree with you that mat files can be opened from command line. However, expected functionality is such that user will save base workspace after some processing through GUI and in the next session he can open the saved base workspace through GUI instead of searching the .mat file.

Sign in to comment.

Asked:

on 11 Aug 2016

Commented:

on 12 Aug 2016

Community Treasure Hunt

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

Start Hunting!