I want to save my plotted figure in MATLAB to a fig
file. Currently I'm using the following code:
hf1 = figure();
p1=uipanel('Parent',hf1);
a1=subplot(2,1,1,'Parent',p1);
%b1=plot(a1,1:9);
b1=bar(a1,1:9);
a2=subplot(2,1,2,'Parent',p1);
b2=bar(a2,1:9);
%b2=plot(a2,1:9);
hf2 = figure('Visible', 'on');
hAxes = copyobj(findobj(p1,'Type','Axes'), hf2);
saveas(hf2,'case2.fig','fig');
But then I get the following error:
??? Error using ==> getProxyValueFromHandle at 15 Input must be a valid handle.
Error in ==> plotedit at 91 [varargout{1:nargout}] = feval(args{:});
Error in ==> specgraph.barseries.preserialize at 10 peerVals = plotedit({'getProxyValueFromHandle',hPeers});
Error in ==> hgsaveStructDbl at 81 olddata{i} = {hh,preserialize(hh)};
Error in ==> hgsave at 63 hgS = hgsaveStructDbl(h, SaveAll);
Error in ==> saveasfig at 7 hgsave( h, name );
Error in ==> saveas at 126 feval( ['saveas' format], h, name )
Error in ==> testbar at 11 saveas(hf2,'case2.fig','fig');
But when I replace the bar
with plot
in the code (I commented them out now^^), then I can save the figure successfully.
The version I'm using is MATLAB R2010a.