MATLAB Answers

## Rearranging Array Rows into Multiple Blocks while Maintaining the Old Order

Asked by Saeid

### Saeid (view profile)

on 18 Mar 2019
Latest activity Commented on by Saeid

### Saeid (view profile)

on 18 Mar 2019
Accepted Answer by Jos (10584)

### Jos (10584) (view profile)

How can I rearrange an array from alternating rows to multiple blocks, maintaining the order of the rows?

madhan ravi

### madhan ravi (view profile)

on 18 Mar 2019
please illustrate with a input and the desired output as text instead of picture
Saeid

### Saeid (view profile)

on 18 Mar 2019
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];

Sign in to comment.

## 2 Answers

### Jos (10584) (view profile)

Answer by Jos (10584)

### Jos (10584) (view profile)

on 18 Mar 2019
Accepted Answer

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

#### 0 Comments

Sign in to comment.

### madhan ravi (view profile)

Answer by madhan ravi

### madhan ravi (view profile)

on 18 Mar 2019
Edited by madhan ravi

### madhan ravi (view profile)

on 18 Mar 2019

reshape(matrix,[],size(matrix,2))

Saeid

### Saeid (view profile)

on 18 Mar 2019
Thanks Madhan!

Sign in to comment.