MATLAB: Reshape array by moving row below to end of column above

array indexingMATLABreshape

Hello all,
I have run into a unique reshaping problem and would greatly appreciate any help.
Say I have an array:
A= (1:63)';
Within "A" there are "n" chunks of data that need to be sorted. In this example, there are 3 chunks of data each with 21 values.
n = 3;
I need to reshape "A" into a horizontal row vector "B" with the following pattern:
B = [1 22 43 2 23 44 3 24 45 …..]
I am working on a very large optimization problem so I am trying to avoid any loops if possible.
I greatly appreciate any possible solutions or if someone can point me in the right direction,
-Chris H.

Best Answer

reshape(reshape(A, [], n).', 1,[])