필터 지우기
필터 지우기

Is it possible to show two .fig files in the same figure?

조회 수: 28 (최근 30일)
Raj
Raj 2023년 6월 10일
답변: Walter Roberson 2023년 6월 10일
Dear All,
I am able to display two .fig files in the same figure as in the code below (like hold on function). However, I'm pretty sure I'm doing something wrong. Because, instead of one, two figures are opened. Also, I can't set the axis limits in any way.
openfig('try1.fig');
fig = gcf;
openfig('try2.fig');
hAxes = findobj(fig, 'Type', 'axes');
copyobj(allchild(gca), hAxes);
Any thoughts?

답변 (2개)

Walter Roberson
Walter Roberson 2023년 6월 10일
figures are the top-level documented visible graphics objects. .fig files represent figures. It is not possible to display two .fig files in one figure. You can take the graphics contents of two distinct figures and copy the contents to a common figure; @Matt J's approach using copyobj() is good for that purpose.
But a figure is a graphical object combined with behaviour and if you had two figures with different behaviours and tried to combine them, you would have problems. If one figure defined left mouse button press as zoom, but the second figure defined left mouse button press as starting to draw a line, then you cannot combine the two behaviours into one figure.
There is at least one undocumented or poorly documented graphics container that can have figures as children. If you invoke volumeViewer() then several figures are generated inside some kind of container. At one point I did a bit of tracking about the properties of that container, but I have forgotten the details now.

Matt J
Matt J 2023년 6월 10일
편집: Matt J 2023년 6월 10일
I am able to display two .fig files in the same figure as in the code below (like hold on function).
When you use hold on/off, the plotting commands are not generating new figures. They are generating new child objects (lines, scatter, images) in the current axes. You would have to obtain the handles to the Children of the two different axes and parent them, or copies of them, to a 3rd axes. Example:
H1=figure;
plot(rand(1,5),'-rx'); title 'Plot 1'
H2=figure;
plot(rand(1,5),'--bo'); title 'Plot 2'
figure;
hAxes=axes;
h=findobj([H1,H2],'Type','Line');
copyobj(h,hAxes); title 'Copy Plot'

카테고리

Help CenterFile Exchange에서 Graphics Object Programming에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by