Combine multiple figures (.fig) with subplots into one figure.

11 views (last 30 days)
I have two (.fig) files; a.fig and b.fig.
a.fig contains four plots (each with their own colorbars) in a 2x2 grid; b.fig contains two loglog plots in a 2x1 layout, with a legend on each plot
I used the code below to create b.fig from two individual .fig files, however I would like all the plots to be in one figure, but I don't how to modify the code below to do this. (when creating b.fig using the code below I had trouble with plotting the legend so I used 'sub-plot-legend' from the file exchange to replot the legend).
% Open old figures.
gu = open('gugu.fig');
gu_ax = gca;
lu = open('lulu.fig');
lu_ax = gca;
F = figure; % New figure
P1 = subplot(1,2,1); % Plot a subplot.
P1_pos = get(P1,'position'); % get its position.
delete(P1) % Delete the subplot
P2 = subplot(1,2,2);
P2_pos = get(P2,'position');
delete(P2);
P = copyobj(gu_ax,F); % Copy the gu_ax to new fig
set(P,'position',P2_pos) % Set its position to the deleted subplot's
P = copyobj(lu_ax,F);
set(P,'position',P1_pos)
Any help would be much appreciated. Thanks

Answers (1)

Walter Roberson
Walter Roberson on 1 Feb 2011
I don't think you should count on gu's axes being the current axes after the open(). It would probably be safer to use
gu_ax = findobj(gu, 'type', 'axes');
and correspondingly
lu_ax = findobj(lu, 'type', 'axes');

Categories

Find more on Specifying Target for Graphics Output in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!