Efficient reordering of vector

1 view (last 30 days)
ak135AK
ak135AK on 3 Dec 2015
Commented: Guillaume on 3 Dec 2015
I would like to reorder vector as following:
a = [1 2 3 4 5 6 7 8 9 10 11 12]
to
r = [1 5 9 2 6 10 3 7 11 4 8 12]
what would be efficient way of doing so?

Accepted Answer

Walter Roberson
Walter Roberson on 3 Dec 2015
reshape( reshape(a, 4, 3).', 1, [])
  3 Comments
Walter Roberson
Walter Roberson on 3 Dec 2015
In that line, "stride" would have to mean the number of elements in each sub-group. I tend to instead think of stride in terms of the difference between adjacent indices, and for that you would use
reshape(reshape(a,stride,[]).' 1, [])
Guillaume
Guillaume on 3 Dec 2015
That is also what I meant, but... brain did not engage properly.

Sign in to comment.

More Answers (0)

Categories

Find more on Read, Write, and Modify Image in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!