Rearranging Array Rows into Multiple Blocks while Maintaining the Old Order

2 次查看(过去 30 天)
How can I rearrange an array from alternating rows to multiple blocks, maintaining the order of the rows?
  2 个评论
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 CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by