2012-02-08 64 views
2

我有很多圖。 我需要對這些圖進行一些格式化。就像我需要更改標籤一樣,畫幾行然後放置圖例,在所有這些圖表上格式化字體大小和顏色等。這些圖形是.fig文件。Matlab重複使用圖例和格式

我沒有圖形數據點和生成代碼選項需要很長時間來處理。而情節是散點圖。

有沒有一種方法可以在所有這些圖形上使用相同的格式。像打開所有的無花果,並通過編碼做一些數字屬性編輯?或創建一個格式並可以在所有數字上應用? (smthing像格式漆)

感謝

回答

1

MATLAB的數字是複雜的分層對象,所以這將是幾乎不可能使一個普遍的「格式刷」。

您可以獲得圖,軸,線等的屬性作爲結構,但其中許多屬性是隻讀的。

如果您正在處理簡單的數字 - 一個座標軸,相似類型的圖,相同數量的數據序列,沒有手動註釋 - 可能更簡單的方法是從一個圖中獲取數據並將其應用於您想要的圖用作標準。

如果你的圖形全是分散的,則對象類型可以是行(如果使用plot)或hggroup(如果使用scatter)。所以他是一個如何實現的例子。

fstd = hgload('standard.fig'); %# load standard figure 
f1 = hgload('f1.fig'); %# load another figure 
%# find data series objects 
hstd = findobj(gcf,'type','line','-or','type','hggroup'); 
h1 = findobj(gcf,'type','line','-or','type','hggroup'); 
assert(numel(hstd)==numel(h1),'Figures have different number of data series') 
%# get the data coordinates from one figure and apply to another 
for k = 1:numel(hstd) 
    h1x = get(h1(k),'XData'); 
    h1y = get(h1(k),'YData'); 
    h1z = get(h1(k),'ZData'); 
    set(hstd(k),'XData',h1x); 
    set(hstd(k),'YData',h1y); 
    set(hstd(k),'ZData',h1z); 
end 
hgsave(hstd,'f1mod.fig') %# save the modified figure 
1

如果我理解正確,您應該能夠一次只打開一個數字,然後應用所需的格式。例如:

fileList = dir('*.fig') 
for ix = 1:length(fileList) 
    h = open(fileList(ix).name); 

    %Now operate on the figure with handle h 
    %e.g. 
    axis(h,[0 10 -3 3]); 
    legend(h,'Data1','Data2'); 
    hold on 
    plot(-10:10, x.^2,'k-'); 

    %Then get whatever output you want, e.g. save, print, etc. 
end