How to reshape matrix in this way?

1 vue (au cours des 30 derniers jours)
John
John le 12 Nov 2014
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.

Réponses (1)

Roger Stafford
Roger Stafford le 13 Nov 2014
Modifié(e) : Roger Stafford le 13 Nov 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);

Catégories

En savoir plus sur Resizing and Reshaping Matrices dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by