7

Matlab reusing captions and formatting

 3 years ago
source link: https://www.codesd.com/item/matlab-reusing-captions-and-formatting.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Matlab reusing captions and formatting

advertisements

I have a number of graphs. I need to do some formatting over those graphs. Like i need to change labels, draw a few lines then place the legends,format the font size and colors etc over all those graphs. These graphs are .fig files.

I do not have the graph data points and generate code option is taking a very long time to process. And the plots are scatter plots.

Is there a way I can use the same formatting over all these graphs . Like open all the figs and do some figure property editing by coding ? or create a formatting and can apply over that over all the figures ? (smthing like format paint )

Thanks


MATLAB figures are complex hierarchical objects, so it would be almost impossible to make a universal "format painter".

You can get the properties of figure, axes, line, etc as a structure, but many of them are read-only.

If you are dealing with simple figures - one axes, similar types of plots, same number of data series, no manual annotations - probably the easier way would be get the data from one figure and apply them to the figure you want to use as a standard.

If your figure are all scatter, the object type is either line (if you use plot), or hggroup (if you use scatter). So he is an example how it can be done.

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




About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK