How to plot two .fig file as subplots in a new figure window ?
1 次查看(过去 30 天)
显示 更早的评论
采纳的回答
Jonas
2022-12-12
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
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!