|
I have paired (x,y) data. I want to compute a sort of moving average on
it, and I want values returned at the same values of x. The kink is
that the x data is not equally spaced.
I've solved the problem this way:
y =
ksdensity(x,x,'kernel','box','weights',y)./ksdensity(x,x,'kernel','box');
But it's dreadfully slow. I have to call ksdensity twice, once with
weighting and once without. The first one is to basically sum the
points within a kernel and the second one is to count the points within
a kernel. (ie. mean=sum/N)
[The size of the kernel isn't terribly important, so I've stuck with the
defaults.]
Is there a better way to do this? I thought about rounding +
convolution, but it would require interpolation and I'm not sure how
willing I am to put up with roundoff error. Although at this stage, it
might be worth it...
|