필터 지우기
필터 지우기

Combining existing figures, each in its own tile

조회 수: 75 (최근 30일)
Chris Koen
Chris Koen 2022년 9월 22일
댓글: Ahmed Mahfouz 2024년 2월 27일
I have three figures, each in a .fig file. I want
to combine these, in a subplot-type layout
(i.e. each in a separate tile). Is there a way of doing
this retaining the properties of the figures (e.g. fonts,
axis scales, axis inversions, etc?

채택된 답변

dpb
dpb 2022년 9월 22일
It's pretty easy if just copying an axes and its content to a new figure; when it's a new axes that's been created with either subplot or nexttile, then have to select the components under the axes and put them in the new one.
I tried with tiledlayout for the first one after
hF=openfig('yourfirstsaved.fig');
TLO=tiledlayout(3,1);
nexttile
copyobj(copyobj(hF.Children,get(hF.Children,'Type')),TLO)
worked as desired; however, after
nexttile
I couldn't figure out any way to point the target of a similar copyobj to the TLO handle that directed it to the next tile successfully; by default it kept putting new copies on top of the same first tiled axis.
Trying
copyobj(copyobj(hF1.Children,get(hF1.Children,'Type')),gca)
resulted in
Error using copyobj
Axes cannot be a child of Axes.
since then the target is the axes handle so trying to shortcircuit to copy the whole axes, etc., can't work because there's already an axes.
So, then it becomes more work to pick the sub-pieces and some pieces may not get copied depending on the content in the figure.
  댓글 수: 3
dpb
dpb 2022년 9월 24일
편집: dpb 2022년 9월 24일
I don't see any alternative, no. But, you should be able to use the expanded search capabilities of findobj to return everything from the figure from the axes down...now whether that will then reproduce the figure in all its glory or not depends on what all is in the figure -- legends may be an issue, for example.
Ahmed Mahfouz
Ahmed Mahfouz 2024년 2월 27일
I just had the same problem and I could work out a way to copy the axes into tiles other than the first one.
Adding to what @dpb suggested, you can try the following lines to avoid stacking the axes on top of each other in the first tile:
listOfFigNames = {'fig1.fig', 'fig2.fig', 'fig3.fig'};
nFigs = length(listOfFigNames);
tl = tiledlayout(nFigs, 1);
for i =1:nFigs
hF_temp = openfig(listOfFigNames{i});
ax_temp = copyobj(copyobj(hF_temp.Children, get(hF_temp.Children,'Type')), tl);
ax_temp(1).Layout.Tile = i;
end

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

추가 답변 (1개)

Karl_469
Karl_469 2023년 11월 2일

카테고리

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