Efficient reordering of vector

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?

 採用された回答

Walter Roberson
Walter Roberson 2015 年 12 月 3 日

0 投票

reshape( reshape(a, 4, 3).', 1, [])

3 件のコメント

Guillaume
Guillaume 2015 年 12 月 3 日
or more generically
reshape(reshape(a, [], stride).', 1, [])
Walter Roberson
Walter Roberson 2015 年 12 月 3 日
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 2015 年 12 月 3 日
That is also what I meant, but... brain did not engage properly.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMATLAB Coder についてさらに検索

タグ

質問済み:

2015 年 12 月 3 日

コメント済み:

2015 年 12 月 3 日

Community Treasure Hunt

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

Start Hunting!

Translated by