How to plot two .fig file as subplots in a new figure window ?

2 views (last 30 days)
I want to create a single figure window conataining both the .fig files as subplots. Help is deeply appreciated.

Accepted Answer

Jonas
Jonas on 12 Dec 2022
here a kind of manual solution, adapted from the function given on file exchange:
h(1) = openfig('fog.fig','invisible');
ax(1)=gca;
h(2) = openfig('snow.fig','invisible');
ax(2)=gca;
N=numel(h);
figure;
for i=1:N
% create and get handle to the subplot axes
s(i) = subplot(N,1,i);
% get handle to all the children in the figure
aux=get(ax(i),'children');
for j=1:size(aux)
fig(i) = aux(j);
copyobj(fig(i),s(i));
hold on
end
% copy children to new parent axes i.e. the subplot axes
xlab = get(get(ax(i),'xlabel'),'string');
xlabFontSize= get(get(ax(i),'xlabel'),'FontSize');
xlabInterpreter = get(get(ax(i),'xlabel'),'Interpreter');
ylab = get(get(ax(i),'ylabel'),'string');
ylabFontSize = get(get(ax(i),'ylabel'),'FontSize');
ylabInterpreter = get(get(ax(i),'ylabel'),'Interpreter');
tit = get(get(ax(i),'title'),'string');
titFontSize = get(get(ax(i),'title'),'FontSize');
titInterpreter = get(get(ax(i),'title'),'Interpreter');
hasLegend=~isempty(findobj(h(i),'type','legend'));
if hasLegend
lgText = get(get(ax(i),'legend'),'string');
lgLocation = get(get(ax(i),'legend'),'Location');
end
xLimits = get(ax(i),'XLim');
yLimits = get(ax(i),'YLim');
xGrid = get(ax(i),'XGrid');
yGrid = get(ax(i),'YGrid');
ScaleX = get(ax(i),'Xscale');
ScaleY = get(ax(i),'Yscale');
TickX = get(ax(i),'Xtick');
TickY = get(ax(i),'Ytick');
TicklabelX = get(ax(i),'Xticklabel');
TicklabelY = get(ax(i),'Yticklabel');
set(gca, 'XScale', ScaleX, 'YScale', ScaleY, 'Xtick', TickX, 'Ytick',...
TickY, 'Xticklabel', TicklabelX, 'Yticklabel', TicklabelY,'XGrid',xGrid,'YGrid',yGrid);
xlabel(xlab,'FontSize',xlabFontSize,'Interpreter',xlabInterpreter);
ylabel(ylab,'FontSize',ylabFontSize,'Interpreter',ylabInterpreter);
title(tit,'FontSize',titFontSize,'Interpreter',titInterpreter);
xlim(xLimits);
ylim(yLimits);
if hasLegend
legend(lgText,'Location',lgLocation)
end
end

More Answers (0)

Categories

Find more on Axes Appearance 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!