Trouble loading GUI variables into handles
1 view (last 30 days)
Show older comments
Guys -
This one's driving me nuts. I want to save the state of my GUI with many pushbuttons and text windows so that when I load the saved .mat file later the values will be put back into the handles structure and the GUI will look like it did when I saved it. I can save the GUI state vector just fine this way:
state.KMCsource = get(handles.KMCsource);
state.sourceKmeansVRC = get(handles.sourceKmeansVRC);
state.sourceFCM = get(handles.sourceFCM);
state.FCMXBVRC = get(handles.FCMXBVRC);
state.KMsourceclust = get(handles.KMsourceclust);.
.
.
and so on, and I end up with a structure variable called 'state' that contains the complete handles data for all the elements of my GUI. The problem comes when I reopen the GUI and want to pass all this data into the GUI handles and have the GUI reflect the configuration of the state in which it was last saved. When I attempt:
set(handles.KMCSource,state.KMCsource);
I get the "invalid handle object' error because at this point the GUI handles are just floating point numbers that don't seem to point to the GUI elements. So my question is this: Once I have saved all the relevant handle data in a structure called 'state', how do I get that data back into handles such that the GUI looks the way it did when I closed it?
0 Comments
Answers (2)
Jan
on 6 Mar 2012
Handles are in fact floating point numbers. As long as the corresponding element is not deleted, a handle is a unqiue address of an object.
How do you obtain the handles struct after re-creating the figure? Do you try to use the former handles?
0 Comments
Walter Roberson
on 7 Mar 2012
If you are restoring at a point where the old graphics are gone (e.g., after re-starting the program), then you will have to create uicontrol and text objects corresponding to each control that will be re-set; then you can set() their state.
You will probably run in to notable problems because not all properties that can be get() can be set().
You also have to watch out for hidden properties, and you will have to watch out because some fields of some graphics objects will contain graphics object references to objects you did not explicitly create (e.g., titles on axes objects)
There is another problem you will face that will lead to problems: you will be wanting to re-create the hierarchy. When you are "live" the hierarchy is expressed through the 'Parent' and 'Children' properties. You can save those properties but restoring them is going to lead to problems as they are graphics handles that will refer to the old numbering.
All in all, you might find it a lot easier to saveas() your figure and let the MATLAB serialization routines take care of all the details.
3 Comments
See Also
Categories
Find more on Printing and Saving 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!