How to reorder matrix?

I have a matrix
[1 6;2 7;3 8;4 9;5 10]
and i want to change the order into [1 2;3 4; 5 6;7 8;9 10]
any idea how to do this? i have tried reshape and transpose but didn't work well. thanks

Respuestas (2)

Matt J
Matt J el 30 de Jul. de 2015
Editada: Matt J el 30 de Jul. de 2015

0 votos

A=[1 6;2 7;3 8;4 9;5 10]
Anew=reshape(A,size(A,2),[]).'
Sebastian Castro
Sebastian Castro el 30 de Jul. de 2015
Editada: Sebastian Castro el 30 de Jul. de 2015

0 votos

You were close! The missing part was reshaping the matrix to its "flipped size" prior to transforming it.
origMatrix = [1 6;2 7;3 8;4 9;5 10];
origSize = size(origMatrix);
flippedSize = fliplr(origSize);
reshapedMatrix = reshape(origMatrix,flippedSize);
finalMatrix = transpose(reshapedMatrix);
... or, the awfully condensed version:
origMatrix = [1 6;2 7;3 8;4 9;5 10];
finalMatrix = reshape(origMatrix,fliplr(size(origMatrix)))';
- Sebastian

Preguntada:

el 30 de Jul. de 2015

Editada:

el 30 de Jul. de 2015

Community Treasure Hunt

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

Start Hunting!

Translated by