2.57 How to find mean of equal sized segments of a vector

Given vector \(V\) of length \(m\) find the mean of segments \(V(1:n),V(n+1:2n),V(2n+1:3n)\dots \). In otherwords, equal length segments.

Mathematica

len = 52; n = 4; 
v   = RandomReal[{0, 1}, len]; 
Mean /@ Partition[v, n]
 

{0.750653,0.410073,0.401005, 
0.138907,0.466247,0.568257, 
0.535362,0.517755,0.555368, 
0.705857,0.502319,0.453571,0.357949}
 

 

Matlab

N = 52; 
n = 4; 
V = rand(N,1); 
mean(reshape(V,n,N/n))'
 

ans = 
    0.3026 
    0.3589 
    0.4745 
    0.6249 
    0.3042 
    0.5428 
    0.2387 
    0.3200 
    0.6224 
    0.4408 
    0.5657 
    0.5469 
    0.5696