MATLAB Answers

Merging two figures

687 views (last 30 days)
Mateusz
Mateusz on 24 Mar 2011
Commented: David Hasin on 27 May 2020
I have two figures with different plots. I would like to merge them into one figure that contains both plots and with keeping the title of the figure and axis-labels (both figures have the same title and axis-labels). How can I do this in Matlab? I should also add that I am not interested in "do-by-hand" solution.

  0 Comments

Sign in to comment.

Accepted Answer

Matt Fig
Matt Fig on 24 Mar 2011
As an example,
figure(50)
plot(0:.01:1)
figure(60)
plot((0:.01:1).^2)
Now, do this:
L = findobj(50,'type','line');
copyobj(L,findobj(60,'type','axes'));
If you have different figure numbers, put them in place of the 50 and 60.

  6 Comments

Show 3 older comments
Walter Roberson
Walter Roberson on 22 May 2018
You can use the kind of code I showed in https://www.mathworks.com/matlabcentral/answers/262265-duplicating-an-imshow-image-into-a-new-figure-without-using-imshow#comment_332459, just looping with f1 set to each source figure in turn.
Lorenzo Mattera
Lorenzo Mattera on 14 Mar 2020
sorry for the silly question but ..
once one has performed the
L = findobj(50,'type','line');
copyobj(L,findobj(60,'type','axes'));
how do you plot the result (superimposed plots)?
any way to keep colors and legend of the individual (original) figures?
thank you
Renzo
David Hasin
David Hasin on 27 May 2020
Woked great, thanks!

Sign in to comment.

More Answers (3)

Ali Benmabrouk
Ali Benmabrouk on 21 Jan 2015
Hello Friends, I have to merge two matlab figures (please take a look on the images below) in one figure in order to compare contours. How can do that??? Thank you so much.

  0 Comments

Sign in to comment.


Chunguo Wu
Chunguo Wu on 23 Jan 2016
I'm also caring about this issue.

  0 Comments

Sign in to comment.


Community Treasure Hunt

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

Start Hunting!