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

12 vues (au cours des 30 derniers jours)
SanSun
SanSun le 5 Août 2020
Commenté : Rena Berman le 8 Oct 2020
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 commentaires
John D'Errico
John D'Errico le 21 Sep 2020
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 le 8 Oct 2020
(Answers Dev) Restored edit

Connectez-vous pour commenter.

Réponses (1)

Arthur Roué
Arthur Roué le 6 Août 2020
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';

Catégories

En savoir plus sur Printing and Saving dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by