从Matlab .fig文件中读取数据,并重新绘图

本文转自:http://blog.csdn.net/vernice/article/details/47034489

Matlab提供了强大的函数集合,可以从.fig文件中读取图中的数据,并重新绘制图形。如果原始数据丢失,我们可以从.fig文件中恢复原始数据,并基于原始数据做进一步的处理。


以下是一个从两个不同文件中读取原始数据,并重新绘制图形的例子。

[plain]  view plain  copy
  1. h1 = openfig('1.fig','reuse'); % open figure  
  2. D1=get(gca,'Children'); %get the handle of the line object  
  3. XData1=get(D1,'XData'); %get the x data  
  4. YData1=get(D1,'YData'); %get the y data  
  5. Data1=[XData1' YData1']; %join the x and y data on one array nx2  
  6.   
  7. h2 = openfig('2.fig','reuse'); % open figure  
  8. D2=get(gca,'Children'); %get the handle of the line object  
  9. XData2=get(D2,'XData'); %get the x data  
  10. YData2=get(D2,'YData'); %get the y data  
  11. Data2=[XData2' YData2']; %join the x and y data on one array nx2  
  12.   
  13. figure;  
  14. plot( XData1{1}, YData1{3}, 'r-o', XData1{1}, YData1{2}, 'r--^', XData1{1}, YData1{1},'r-d', XData1{1}, YData2{3}, 'b-o', XData1{1}, YData2{2}, 'b--^', XData1{1}, YData2{1},'b-d','linewidth',1.5,'markersize',8);  
  15. legend('a','b','c','d','e','f');  
  16. xlabel('Number','fontsize',12);  
  17. ylabel('overhead','fontsize',12);  
  18. title('number and overhead')  

猜你喜欢

转载自blog.csdn.net/deng_sai/article/details/75213364