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

1 回表示 (過去 30 日間)
RAJEEV
RAJEEV 2022 年 12 月 12 日
コメント済み: RAJEEV 2022 年 12 月 12 日
I want to create a single figure window conataining both the .fig files as subplots. Help is deeply appreciated.

採用された回答

Jonas
Jonas 2022 年 12 月 12 日
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
  1 件のコメント
RAJEEV
RAJEEV 2022 年 12 月 12 日
Thank You. It worked with very little change.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGrid Lines, Tick Values, and Labels についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by