GUI developed in Matalb 2013b behaving weirdly in Matlab 2015a

1 次查看(过去 30 天)
I created a GUI with few buttons in it. I'm storing workspace variables in a .mat file for a callback and loading the same mat file while calling another callback
func1_callback
{
x=1;
y=2;
set_param(handles, '<property>', 'value');
save xyz.mat
}
func2_callback
{
load xyz.mat
...
...
}
The callbacks are associated to two different buttons on the GUI. When I click on second button a separate instance of GUI opens up.. this happens for every callback/function where i'm loading mat file
Any solutions/suggestions to get rid of this issue?

采纳的回答

Walter Roberson
Walter Roberson 2015-5-4
I speculate this might related to the switch to hg2 (Handle Graphics 2), but that is speculation.
When you use save without any variable names, you are asking to save everything in the current workspace. That is going to include your handles structure. Now that graphics handles are not just numbers that are looked up internally to find the graphics object, you are effectively storing the graphics objects in the save file. And loading them when you load(), with uncertain effects.
You should only save() the variables you need. You should also consider only load()'ing the variables you need at the time. You should also get in the habit of not using load in command form and should switch to function form in which the value returned from load() is a structure containing the variables.
savedvals = load('xyz.mat');
disp(savedvals.x ^3 + sinh(savedvals.y * pi))

更多回答(1 个)

Mike Garrity
Mike Garrity 2015-5-4
My guess would be that you have handles to graphics objects in your workspace when you save the MAT file. Consider the following example:
h = plot(1:10)
save my_file.mat
At this point, my_file.mat contains h. In earlier versions of MATLAB, h was just a double with a funny value like 156.0025. But starting in 14b, it's actually the handle of the Line object that plot created. When you load that MAT file back into MATLAB, you're going to get that Line object back.
In your case, you probably want to either use a form of save where you list the variables you want to save:
save('xyz.mat','x','y')
Or call clear before save to get rid of anything you don't want saved in the file:
clear('h')
save('xyz.mat')

类别

Help CenterFile Exchange 中查找有关 Whos 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by