rearranging a matrix and changing it dimensions

1 visualización (últimos 30 días)
PIRIL
PIRIL el 16 de Oct. de 2015
Editada: Mohammad Abouali el 16 de Oct. de 2015
Hello all,
I have a 104x1000 matrix and I want to reaarange it and have 26x4000 instead.
Lets say that I have a matrix A= [1 2 3; 2 4 5; 3 6 7; 4 5 7] and I want to rearrange it by concatenating 2 rows and have a matrix like this instead X=[1 2 3 2 4 5; 3 6 7 4 5 7].
Could anyone help me ?
Thanks..

Respuesta aceptada

Mohammad Abouali
Mohammad Abouali el 16 de Oct. de 2015
Editada: Mohammad Abouali el 16 de Oct. de 2015
use reshape() command:
However, MATLAB rearranges using column order. You are interested in the row base. so you need to do some additional transposing like this:
X=reshape(A',4000,26)';
note that there are two transposes. also check that instead of 26x4000 in the reshape command we are using 4000x26 (due to transpose the final result, i.e. X, would be of size 26x4000). Here is the full code for you example:
A= [1 2 3; 2 4 5; 3 6 7; 4 5 7]
A =
1 2 3
2 4 5
3 6 7
4 5 7
X=reshape(A',[],2)'
X =
1 2 3 2 4 5
3 6 7 4 5 7

Más respuestas (0)

Categorías

Más información sobre Matrices and Arrays en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by