フィルターのクリア

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 Center および File ExchangeGraphics Object Programming についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by