## How to access n vector elements, then skip n elements, then access the following n elements and so on?

### Michal Knapek (view profile)

on 14 Jun 2018
Latest activity Edited by Michal Knapek

on 14 Jun 2018

### Stephen Cobeldick (view profile)

I would like to access vector elements like this:
a_new = [a(1:10) a(21:30) a(41:50) ... ]
Is there any elegant way how to do that without loops?
The vector is huge, so something like
k=[];
n=10;
for i=1:floor(length(a)/n)
if mod(i,2)==0
kk=((i-1)*n):((i)*n);
k=[k kk];
end;
end;
a_new=a(k);
cannot be used.
Thanks, Michal

### Stephen Cobeldick (view profile)

on 14 Jun 2018
Edited by Stephen Cobeldick

### Stephen Cobeldick (view profile)

on 14 Jun 2018

Assuming that the number of elements of your vector A is exactly divisible by 20:
M = reshape(A,20,[])
V = M(1:10,:)
V = reshape(V,1,[])
If required, pad/trim the vector A to make it a suitable length.

Michal Knapek

### Michal Knapek (view profile)

on 14 Jun 2018
Works perfectly, thanks!