Reshape array by moving row below to end of column above

2 views (last 30 days)
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.
  1 Comment
Christopher
Christopher on 26 Feb 2020
Walter,
Thank you very much for your prompt and concise answer, it was exactly what I was looking for!
-Chris H.

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 26 Feb 2020
reshape(reshape(A, [], n).', 1,[])

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!