2012-07-10 73 views
0

我想將我在MATLAB中繪製的圖保存到fig文件中。目前我使用下面的代碼:在子圖中保存條形圖

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'); 

但後來我得到以下錯誤:

??? 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');

但是,當我與代碼中plot更換bar(我現在評論出來^^ ),那麼我可以成功保存這個圖。

我使用的版本是MATLAB R2010a。

+0

你真的需要先複製數字到一個新的?你爲什麼不用'saveas(hf1,'case2.fig','fig');'在這裏工作! – 2012-08-17 08:33:40

+0

很奇怪。也許您應該使用MathWorks提交支持憑單。或者先嚐試升級到最新版本。 – bdecaf 2012-08-17 08:58:56

+0

Mathworks錯誤報告[here](http://www.mathworks.com/support/bugreports/469597) – Doresoom 2013-07-09 15:18:50

回答

1

嘗試使用此代碼

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

代替

b=bar(a1,1:9);