2012-02-08 160 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