How to open multiple figures and combine them into a new figure

11 次查看(过去 30 天)
Hello, I have multiple open figures. I want to create a new figure containing all the figures. How can I do this?
I tried this :
clear all
clc
%%Oppening figure
rep = 'C:s';
if exist(rep, 'file')~=7
error('Le dossier n''existe pas');
end
ext = '*.fig';
chemin = fullfile(rep,ext);
list = dir(chemin);
nFig = length(list);
figure; % new figure
for n = 1:nFig
filename = fullfile(rep,list(n).name);
f_c = openfig(filename,'reuse');
ha1 = get(gca(n+1),'Children'); %this returns the children of the axes
a1 = get(ha1,'Xdata'); % obtain the XData
b1 = get(ha1,'Ydata'); % obtain the YData
% close('all')
hold on
plot(a1,b1) %plot the data again
dockfig('all')
end
nFig = length(list);
figure; % new figure
for n = 1:nFig
filename = fullfile(rep,list(n).name);
f_c = openfig(filename,'reuse');
ha1 = get(gca(n+1),'Children'); %this returns the children of the axes
a1 = get(ha1,'Xdata'); % obtain the XData
b1 = get(ha1,'Ydata'); % obtain the YData
% close('all')
hold on
plot(a1,b1) %plot the data again
dockfig('all')
end
Any help will be appreciated. Thanks!
  7 个评论
John D'Errico
John D'Errico 2020-9-21
Note that when you remove your question, you damage answers as a site, since this makes the question useless for anyone else to ever learn from. This insults both the person who wasted their time in answering your question, as well as anyone who might otherwise have also gained from this answer.
If you cannot bear to leave your question in the public, then you should not post in the first place.

请先登录,再进行评论。

回答(1 个)

Arthur Roué
Arthur Roué 2020-8-6
According to your figures, I came with that :
% Get figure handles to merge
hFig_1 = openfig(fullfile(pwd, 'figure_1.fig'));
hFig_2 = openfig(fullfile(pwd, 'figure_2.fig'));
% Find line in axe 2 to copy it into axe 1
hAxe_1 = findobj(hFig_1, 'type', 'Axes');
hLine_2 = findobj(hFig_2, 'type', 'Line');
% Copy line
hLine_21 = copyobj(hLine_2, hAxe_1);
% Change new line style
hLine_21.LineStyle = '--';
hLine_21.Color = 'b';

类别

Help CenterFile Exchange 中查找有关 Printing and Saving 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by