Combining existing figures, each in its own tile
조회 수: 108 (최근 30일)
이전 댓글 표시
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?
댓글 수: 0
채택된 답변
dpb
2022년 9월 22일
See copyobj
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
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
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개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Specifying Target for Graphics Output에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!