How to decompose Structure into its constituent variables from GUI?
Show older comments
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
Chinmay Kirtane
on 11 Aug 2016
Edited: Chinmay Kirtane
on 11 Aug 2016
Adam
on 11 Aug 2016
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.
Chinmay Kirtane
on 12 Aug 2016
Categories
Find more on Whos 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!