If you want a running density, look into c = cumsum(v) density = c[6:end] - c[1:end-5]
If you want in blocks, reshape to a matrix and take the mean along dimension 1. --Tim On Sunday, August 16, 2015 09:08:23 AM paul analyst wrote: > Hi, > How quickly computethe density of the vector in the selected range? > I have vec=[0 0 0 1 0 1 0 1 1 0] > I am lookking for function computing "density" of this vector on selelcted > range i.e. 5 elements : > > foo(vec,5) > result: > [0.2 0.2 0.2 0.2 0.2 0.6 0.6 0.6 0.6 0.6] > > mean first 5 elements is 0.2 > > mean second 5 elements is 0.6 > > etc... > I need somthing fast to veeeery long vectors > Paul
