Combining existing figures, each in its own tile

99 visualizzazioni (ultimi 30 giorni)
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?

Risposta accettata

dpb
dpb il 22 Set 2022
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 Commenti
dpb
dpb il 24 Set 2022
Modificato: dpb il 24 Set 2022
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 il 27 Feb 2024
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

Accedi per commentare.

Più risposte (1)

Karl_469
Karl_469 il 2 Nov 2023

Categorie

Scopri di più su Graphics Object Programming in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by