Here are two other approaches to overall group sizes:
A = [ 1 2 3 4 5 6 7 8 9 ] groupsize = 2;
Approach 1
B = filter( ones(groupsize,1), 1, A ) B = B(groupsize:groupsize:end)
B = 3 7 11 15
Approach 2
B = conv(A,ones(groupsize,1)) B = B(groupsize:groupsize:end)
B = 3 7 11 15 9
Advantage over Divakar , Ratberts and Jolek is that it also works for vectors A that are not divisible by group size. Keep in mind that both of my approaches in this case are slightly different for the last element.
source share