MATLAB: Rearranging a matrix and changing it dimensions

concatenaterearrange

Hello all,
I have a 104×1000 matrix and I want to reaarange it and have 26×4000 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..

Best Answer

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