Setting the size of a tile when loading pre-created matlab figures

8 vues (au cours des 30 derniers jours)
Is it possible to set the size of a tile if you are working with pre-created matlab figures that you need to load?
As answered here, one can load the figures and add them to a new subplot. And as usual you can set the size of the subplot for example like this: s6 = subplot(3,3,[7:9]);
Is this also possible for tiles?
The suggested code for working with tiles from the previously mentioned question:
openfig('fig1.fig');
ax1=gca;
openfig('fig2.fig')
ax2=gca;
figure;
tcl=tiledlayout(1,2);
ax1.Parent=tcl;
ax1.Layout.Tile=1;
ax2.Parent=tcl;
ax2.Layout.Tile=2;
Since this does not use the nexttile function, I wouldn't know where to say how big the tiles should be.
Thank you for your time!

Réponse acceptée

Nirupama Nagarathinam
Nirupama Nagarathinam le 28 Oct 2022
Modifié(e) : Nirupama Nagarathinam le 2 Nov 2022
Yes, it is possible to set the size of tile with "TileSpan" property like that of "subplot" without using "nexttile".
Refer to this modified code:
openfig('fig1.fig');
ax1=gca;
openfig('fig2.fig')
ax2=gca;
figure;
tcl=tiledlayout(2,2); % 2 by 2 tile layout, so 4 tiles available
ax1.Parent=tcl;
ax1.Layout.Tile=1; % placing fig1 in the first tile
% For the figure to span multiple tiles, specify the "TileSpan" property as a two-element vector.
% The first element specifies the number of rows and the second element specifies the number of columns the figure should span.
ax1.Layout.TileSpan=[1 2]; % This code spans fig1 across one row and two columns of tiles starting from tile 1. So it occupies tiles 1 and 2.
ax2.Parent=tcl;
ax2.Layout.Tile=3; % placing fig2 in the third tile
ax2.Layout.TileSpan=[1 2]; % This code spans fig2 across one row and two columns of tiles starting from tile 3. So it occupies tiles 3 and 4.
I have verified the above code in R2019b MATLAB. Though "TileSpan" property was incorporated in the R2019b MATLAB release, it was not mentioned in the R2019b documentation. Hence, refer to this latest documentation link for more details.
  1 commentaire
Douwe Horsthuis
Douwe Horsthuis le 28 Oct 2022
This works perfect. With the added bonus that legends are also transfered into the final figure. Which wasn't the case when I would use subplot.

Connectez-vous pour commenter.

Plus de réponses (0)

Produits


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by