How to reshape matrix in this way?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
When reshape a 3D matrix into 2D matrix, it fills columns first; for example:
a(3,3,4) =
1 1 1
1 1 1
1 1 1
2 2 2
2 2 2
2 2 2
3 3 3
3 3 3
3 3 3
4 4 4
4 4 4
4 4 4
reshape(a,6,6) gives:
d =
1 1 2 3 3 4
1 1 2 3 3 4
1 1 2 3 3 4
1 2 2 3 4 4
1 2 2 3 4 4
1 2 2 3 4 4
How can it be reshaped to:
d =
1 1 1 3 3 3
1 1 1 3 3 3
1 1 1 3 3 3
2 2 2 4 4 4
2 2 2 4 4 4
2 2 2 4 4 4
or
d =
1 1 1 2 2 2
1 1 1 2 2 2
1 1 1 2 2 2
3 3 3 4 4 4
3 3 3 4 4 4
3 3 3 4 4 4
Thanks.
0 comentarios
Respuestas (1)
Roger Stafford
el 13 de Nov. de 2014
Editada: Roger Stafford
el 13 de Nov. de 2014
I think this does it for the first of your desired d's:
d = reshape(permute(reshape(a,3,3,2,2),[1,3,2,4]),6,6);
Added:
The second desired d should be obtained with:
d = reshape(permute(reshape(a,3,3,2,2),[1,4,2,3]),6,6);
0 comentarios
Ver también
Categorías
Más información sobre Resizing and Reshaping Matrices en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!