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
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 CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by