How to create tiledlayout grid in vertical order

Hello,
How to create tiledlayout grid in vertical order?
Let's say I want to create a tiledlayout(3,2), matlab default order is
1 2
3 4
5 6
But I want the lay out to be:
1 4
2 5
3 6
How do I do that?
Thanks,
Ping

 Respuesta aceptada

Dyuman Joshi
Dyuman Joshi el 7 de Nov. de 2023
Editada: Dyuman Joshi el 7 de Nov. de 2023
Change the Tile-indexing to Column Major, the default is Row Major.
tiledlayout(3, 2, 'TileIndexing', 'columnmajor')
nexttile
fplot(@sin, 'k')
title('1')
nexttile
fplot(@cos, 'r')
title('2')
nexttile
scatter(rand(1,10),rand(1,10), [], [1 0 1])
title('3')
nexttile
fplot(@(x) x.^2, 'g')
title('4')
nexttile
fsurf(@(x,y) sin(x)+cos(y))
title('5')
nexttile
fimplicit(@(x,y) x.^2 - y.^2 - 1)
title('6')

5 comentarios

Les Beckham
Les Beckham el 7 de Nov. de 2023
Wow! I didn't know that that option existed. Thanks for teaching me something new today.
You are welcome haha.
It is kinda hidden, as it is not mentioned in the documentation page of tiledlayout.
But if you go this particular page to explore all the properties of tiledlayout, you will find it in the layout subsection - https://in.mathworks.com/help/matlab/ref/matlab.graphics.layout.tiledchartlayout-properties.html
Les Beckham
Les Beckham el 7 de Nov. de 2023
Yeah, I did some digging after seeing your answer and finally found it on that page. Another hidden gem.
ping zhao
ping zhao el 7 de Nov. de 2023
Movida: Sam Chak el 14 de Sept. de 2024
Thank you for all the anwsers!
Ping
ani-per
ani-per el 14 de Sept. de 2024
Thanks Dyuman! That option should really be exposed on the documentation, it's really helpful.

Iniciar sesión para comentar.

Más respuestas (2)

Set up variables:
n_rows = 3;
n_cols = 2;
n = n_rows*n_cols;
data = (1:n)+zeros(10,1);
Default tiledlayout order, for reference:
figure
tiledlayout(n_rows,n_cols)
for ii = 1:n
nexttile()
plot(data(:,ii))
title(sprintf('%d',ii));
xlim([1 10])
ylim([0 n+1])
end
Reordering the layout:
idx = reshape(1:n,n_cols,[]).'
idx = 3×2
1 2 3 4 5 6
figure
tiledlayout(n_rows,n_cols)
for ii = 1:n
nexttile(idx(ii))
plot(data(:,ii))
title(sprintf('%d',ii));
xlim([1 10])
ylim([0 n+1])
end
The tiles are always numbered by row, column, but you can plot into the tiles in whatever order you want by specifying the tile (using Matlab's ordering).
tiledlayout(3,2)
nexttile
title 'First plot'
nexttile(3)
title 'Second plot'
nexttile(5)
title 'Third plot'
nexttile(2)
title 'Fourth plot'
nexttile(4)
title 'Fifth plot'
nexttile(6)
title 'Sixth plot'

Categorías

Más información sobre MATLAB en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 7 de Nov. de 2023

Movida:

el 14 de Sept. de 2024

Community Treasure Hunt

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

Start Hunting!

Translated by