Rearranging Array Rows into Multiple Blocks while Maintaining the Old Order

2 ビュー (過去 30 日間)
Saeid
Saeid 2019 年 3 月 18 日
コメント済み: Saeid 2019 年 3 月 18 日
How can I rearrange an array from alternating rows to multiple blocks, maintaining the order of the rows?
  2 件のコメント
madhan ravi
madhan ravi 2019 年 3 月 18 日
please illustrate with a input and the desired output as text instead of picture
Saeid
Saeid 2019 年 3 月 18 日
The matrix:
[a a a a a;
b b b b b;
c c c c c;
d d d d d;
e e e e e ;
f f f f f ]
should be converted to:
[a a a a a ;
c c c c c;
e e e e e ;
b b b b b;
d d d d d ;
f f f f f];

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

採用された回答

Jos (10584)
Jos (10584) 2019 年 3 月 18 日
You should learn about indexing, one of the most essential aspects of Matlab:
M = randi(4,10,5) ; M(:,1) = 1:size(M,1) % example data
M2 = M([1:2:end 2:2:end], :) % re-ordering the rows

その他の回答 (1 件)

madhan ravi
madhan ravi 2019 年 3 月 18 日
編集済み: madhan ravi 2019 年 3 月 18 日
reshape(matrix,[],size(matrix,2))

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by