Prashant answered well, but I would have a simple correction:
fl = filterLength; A = yourVector (where mod(A,fl)==0) sum(reshape(A,fl,[]),1).'/fl;
There is a ", 1" that makes the string work even with fl == 1 (the original values). I found this when running in a for loop like this:
... read A ... % Plot data hold on; averageFactors = [1 3 10 30 100 300 1000]; colors = hsv(length(averageFactors)); clear legendTxt; for i=1:length(averageFactors) % ------ FILTERING ---------- clear Atrunc; clear ttrunc; clear B; fl = averageFactors(i); % filter length Atrunc = A(1:L-mod(L,fl),:); ttrunc = t(1:L-mod(L,fl),:); B = sum(reshape(Atrunc,fl,[]),1).'/fl; tB = sum(reshape(ttrunc,fl,[]),1).'/fl; length(B) plot(tB,B,'color',colors(i,:) ) %kbhit () endfor
source share