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

조회 수: 13 (최근 30일)
SanSun
SanSun 2020년 8월 5일
댓글: Rena Berman 2020년 10월 8일
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.
Rena Berman
Rena Berman 2020년 10월 8일
(Answers Dev) Restored edit

댓글을 달려면 로그인하십시오.

답변 (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