1. 程式人生 > >從Matlab .fig檔案中讀取資料,並重新繪圖

從Matlab .fig檔案中讀取資料,並重新繪圖

Matlab提供了強大的函式集合,可以從.fig檔案中讀取圖中的資料,並重新繪製圖形。如果原始資料丟失,我們可以從.fig檔案中恢復原始資料,並基於原始資料做進一步的處理。

以下是一個從兩個不同檔案中讀取原始資料,並重新繪製圖形的例子。

h1 = openfig('1.fig','reuse'); % open figure
D1=get(gca,'Children'); %get the handle of the line object
XData1=get(D1,'XData'); %get the x data
YData1=get(D1,'YData'); %get the y data
Data1=[XData1' YData1']; %join the x and y data on one array nx2

h2 = openfig('2.fig','reuse'); % open figure
D2=get(gca,'Children'); %get the handle of the line object
XData2=get(D2,'XData'); %get the x data
YData2=get(D2,'YData'); %get the y data
Data2=[XData2' YData2']; %join the x and y data on one array nx2

figure;
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);
legend('a','b','c','d','e','f');
xlabel('Number','fontsize',12);
ylabel('overhead','fontsize',12);
title('number and overhead')