0

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.

Simon Adcock
  • 3,554
  • 3
  • 25
  • 41
archer
  • 21
  • 3
  • Do you really need to copy the figure first to a new one? why don't you just use `saveas(hf1,'case2.fig','fig');` works here! – Gunther Struyf Aug 17 '12 at 08:33
  • Very strange. Perhaps you should file a support ticket with MathWorks. Or try to upgrade to the recent version first. – bdecaf Aug 17 '12 at 08:58
  • Mathworks Bug Report [here](http://www.mathworks.com/support/bugreports/469597) – Doresoom Jul 09 '13 at 15:18

1 Answers1

1

Try to use this code

b=bar(a1,1:9,'hist');

instead of

b=bar(a1,1:9);