MATLAB: Rearranging a 512×64 matrix into a 32×1024 matrix

arrayexcelMATLABmatrix

I have a 512×64 matrix imported from a excel file. I need to turn it into a 32 x1024 matrix by keeping row 1 column 1 and row 1 column 2 elements in their position and moving all other columns in row 1, and also moving the elements of the other 511 rows.
so row 1 column 3 moves to row 2 column 1
row 1 column 4 moves to row 2 column 2
row 1 column 5 moves to row 3 column 1
row 1 cloumn 6 moves to row 3 column 2
etc… so row 1 transforrms from 1×64 to 32×2
Then move to rearranging row 2
row 2 column 1 moves to row 1 column 3
row 2 column 2 moves to row 1 column 4
I would like to do this for all 512 row until I have a 32 x1024 matrix. I really hope I explained that well enough. I really do not want to have to do this manually in excel so thank you in advance for any help.

Best Answer

% Assuming A is your input matrix of size 512 x 64
% such as
% A=reshape(1:512*64,64,512)';
B = reshape(permute(reshape(A,[512 2 32]),[3 2 1]),[32 1024]);
Related Question