Reshape a multidimensional matrix

4 vues (au cours des 30 derniers jours)
elena galvano
elena galvano le 23 Sep 2020
Commenté : Steven Lord le 23 Sep 2020
i have a multidimensional matrix (146x146x144) that i want to reshape (144x21316). the command reshape works "vertically", how i can reshape "horizontally" ( every rows next to another)

Réponses (2)

madhan ravi
madhan ravi le 23 Sep 2020
Modifié(e) : madhan ravi le 23 Sep 2020
reshape(permute(matrix, [3, 2, 1]), 144, [ ])
  9 commentaires
madhan ravi
madhan ravi le 23 Sep 2020
Modifié(e) : madhan ravi le 23 Sep 2020
reshape(permute(matrix, [2, 1, 3]), 144, []).'
Steven Lord
Steven Lord le 23 Sep 2020
for examplei have a matrix
[ 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 3]
That has one too many 3's in the last row. Correcting that problem:
A = [ 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];
P = reshape(A.', 1, [])
If your A array is actually a 3-dimensional (or generally N-dimensional for N > 2) you're going to want to use permute instead of the .' operator.
P2 = reshape(permute(A, [2 1]), 1, [])
To ask a similar question that madhan ravi did, for this specific array:
B = reshape(1:24, [2 3 4])
What exactly do you want the result of reshaping B to be? Give us the explicit command to create Breshaped:
Breshaped = [ % Fill in numbers here]
Once we know what you want Breshaped to be we can help you write the command to create it.

Connectez-vous pour commenter.


KSSV
KSSV le 23 Sep 2020
iwant = reshape(144,[]) ;
Wont this work for you?
  1 commentaire
elena galvano
elena galvano le 23 Sep 2020
No, the command is wrong

Connectez-vous pour commenter.

Catégories

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

Community Treasure Hunt

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

Start Hunting!

Translated by