Combining multiple existing plots
56 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi,
I have generated multiple MATLAB figures using a code that I have to manually edit each time. Just wondering if there is a way I can combine these pre-existing figures into one figure that shows the data overlapped from each figure.
0 Kommentare
Antworten (1)
Voss
am 13 Mär. 2022
Bearbeitet: Voss
am 13 Mär. 2022
You can try doing something like what follows. This assumes each figure has one axes and you want to put all graphics objects from every figure's axes into a single axes in a new figure. Axes properties such as labels and titles - as well as any legends - will not be preserved, but see if this is at least a step in the right direction. (If the figures you have are saved as .fig files you can use the same approach - just open() each one and subsequently delete() it inside the for loop.)
% first, I create a couple of figures containing some lines
fig_1 = figure();
plot(1:10);
fig_2 = figure();
plot(2:11);
drawnow();
% now combine the figures' contents into a new figure
% specify which "old" figures to use
figs = [fig_1 fig_2];
% make a "new" figure
f = figure();
% get the new figure's axes
ax = gca();
% for each old figure
for ii = 1:numel(figs)
% find all the graphics objects in the figure's axes
obj = findall(get(figs(ii),'CurrentAxes'));
% remove the axes itself
obj(strcmp(get(obj,'Type'),'axes')) = [];
% copy the objects to the new figure's axes
copyobj(obj,ax);
end
0 Kommentare
Siehe auch
Kategorien
Mehr zu Creating, Deleting, and Querying Graphics Objects finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


