Matrix Elements Re-ordering

1 visualizzazione (ultimi 30 giorni)
Pedro Oliveira
Pedro Oliveira il 24 Ott 2017
Commentato: Cedric il 24 Ott 2017
If I have a matrix A that is:
A = [1, 2; 3, 4; 5, 6;7, 8]
How can I reorder it so that it becomes,
A = [1,3;5,7;2,4;6,8]
i.e. basically re.arranging the matrix elements in a row-by-row basis (the first 2 elements of column 1 become the 2 elements in row 1; the second 2 elements of column 1 become the 2 elements in row 2, etc).
Thank you for your help in advance!

Risposta accettata

Cedric
Cedric il 24 Ott 2017
>> B = reshape( A, 2, [] ).'
B =
1 3
5 7
2 4
6 8
  2 Commenti
Pedro Oliveira
Pedro Oliveira il 24 Ott 2017
Thank you!
Cedric
Cedric il 24 Ott 2017
My pleasure!

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Matrices and Arrays in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by