How to merge two figures with multiple plots

2 ビュー (過去 30 日間)
Rokas Zalatorius
Rokas Zalatorius 2017 年 5 月 14 日
回答済み: Cam Salzberger 2017 年 5 月 15 日
Hello,
I have two figures (.fig file). These both figures have 4 plots in them (2x2 layout). I got them from two different Simulink models and want to make visual comparison of each plot. I've tried this code but it just merges one plot and other three plot spaces are left empty. Can someone help me?
% Open old figures.
gu = open('1.fig');
gu_ax = gca;
lu = open('2.fig');
lu_ax = gca;
F = figure; % New figure
P1 = subplot(2,2,1); % Plot a subplot.
P1_pos = get(P1,'position'); % get its position.
delete(P1) % Delete the subplot
P2 = subplot(2,2,2);
P2_pos = get(P2,'position');
delete(P2);
P3 = subplot(2,2,3);
P3_pos = get(P3,'position');
delete(P3);
P4 = subplot(2,2,4);
P4_pos = get(P4,'position');
delete(P4);
P = copyobj(gu_ax,F); % Copy the gu_ax to new fig
set(P,'position',P4_pos) % Set its position to the deleted subplot's
P = copyobj(lu_ax,F);
set(P,'position',P4_pos);
  2 件のコメント
Jan
Jan 2017 年 5 月 15 日
編集済み: Jan 2017 年 5 月 15 日
You forgot to mention what you want as output: 8 diagrams? Or should the lines inside the axes be copied together to the new axes?
The diagrams might be created in a different order in the two original figures. Do some tags determine the position of the subplots?
Rokas Zalatorius
Rokas Zalatorius 2017 年 5 月 15 日
Hello,
So bassicaly I have two figures and each one of it has four plots (2x2 layout). I want to merge/combine those 4 plots from one figure to another respectively of it's position. And in the end get a figure with four plots. So I need to copy four plots from one figure to the new figure and then overlap them with four plots from another figure.
Thank you, Rokas

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

採用された回答

Cam Salzberger
Cam Salzberger 2017 年 5 月 15 日
Hello Rokas,
Rather than copying the axes from the second figure, I think you could just copy the line objects or whatever else is on the axes. It would be easiest to just copy each of the Children of the axes object. Something like:
gu_axes = gu.Children; % Get all the axes on the first figure
lu_axes = lu.Children; % ... second figure
... % set up the new figure if you want to do it on a new figure ...
for k = 1:numel(gu_axes)
copyobj(lu_axes(k).Children,gu_axes(k))
end
-Cam

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by