Extracting x rows every n rows from a table in matlab

Viewed 73

I want to create a new table extracting x rows every n rows from my table. For example if my table is:

1 2 
3 4
5 6
7 8
9 10
11 12
13 14
15 16
17 18
19 20
21 22

I want something like:

1 2
3 4
11 12
13 14
21 22
1 Answers

Here is an easy way by using ismember and mod to categorize the rows

n = 5;
x = 2;
b = a(logical(ismember(mod(0:size(a)-1,n),0:x-1)),:);

such that

>> b
b =

    1    2
    3    4
   11   12
   13   14
   21   22

Data

a = [1 2 
3 4
5 6
7 8
9 10
11 12
13 14
15 16
17 18
19 20
21 22];
Related