Combining existing figures, each in its own tile

104 次查看(过去 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?

采纳的回答

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 中查找有关 Specifying Target for Graphics Output 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by