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.

댓글 수: 1

Ali Benmabrouk
Ali Benmabrouk 2015년 1월 21일
이동: Dyuman Joshi 2023년 11월 23일
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.

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

 채택된 답변

Matt Fig
Matt Fig 2011년 3월 24일

15 개 추천

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.

댓글 수: 10

Walter Roberson
Walter Roberson 2011년 3월 24일
And afterwards, adjust the axes positions and sizes so that the two plots are not on top of each other.
Ernest Chan
Ernest Chan 2015년 12월 25일
Excellent solution: works perfectly!! Thanks!
Imran Rahman
Imran Rahman 2018년 5월 22일
편집: Imran Rahman 2018년 5월 22일
What if I have more than 2 figures to merge? Can you please tell me the code for this. Thank you.
Walter Roberson
Walter Roberson 2018년 5월 22일
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 2020년 3월 14일
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 2020년 5월 27일
Woked great, thanks!
mohammed
mohammed 2022년 8월 15일
i got error
Error using findobj
Invalid handle
Lisette Hernandez Gonzalez
Lisette Hernandez Gonzalez 2023년 11월 23일
A little bit late but for future reference, just change line for Line and it should work. At certain point matlab became case sensitive
L = findobj(50,'type','line');
tells MATLAB to look for line objects starting from the object whose numeric handle is 50 .
In the time since @Matt Fig posted in 2011, MATLAB's graphics interface changed so that now the primary interface the user sees is "handles" instead of numbers for objects.
However, the numeric interface is still present and still works -- especially for the case where the number is a figure number.
Matt's example specifically used figure(50) which asks to create figure with numeric handle 50. That syntax is still in common use, especially with figure(1), figure(2), figure(3), and it is still valid. And if you have created a figure with an integer numeric handle in that way, then findobj() is happy to use the figure number as the first parameter, as long as that figure still exists.
When you use findobj then the 'type' parameter is not case sensitive. The code Matt posted still works exactly as posted
figure(50)
plot(0:.01:1)
figure(60)
plot((0:.01:1).^2)
L = findobj(50,'type','line');
copyobj(L,findobj(60,'type','axes'));

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

카테고리

도움말 센터File Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기

질문:

2011년 3월 24일

이동:

2023년 11월 23일

Community Treasure Hunt

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

Start Hunting!

Translated by