[scilab-Users] moving averager
Alexander Bluem
A.Bluem at fhtw-berlin.de
Mon Jun 23 16:41:12 CEST 2008
Jörg Kühne wrote:
> Dear user list,
>
> have someone experience with moving averager. I should calculate the mean value of a certain amount of bins in a vector. It starts from the lowest bin and ends on the highest bin.
>
> Thanks for your help
>
> best regards
>
> joerg
Hello Jörg,
you could simply run through your vector in a loop. Though I am quite
sure that this "solution" is pretty inefficient, it still works well.
here it is:
//random values
r=floor(rand(1,1000)*1000);
//get size
[nr, nc]=size(r);
//windowsize
wsize=50;
//average vectors
avg=zeros(1:(nc-wsize));
avg2=zeros(1:(nc-wsize));
//iterate through random vector
for i = 1:wsize:(nc-wsize);
//gliding window
avg(i:i+wsize)=mean(r(i:i+wsize));
end
//iterate through random vector
for i = 1:(nc-wsize);
avg2(i)=mean(r(i:i+wsize));
end
clf;
plot(1:nc, r, 'y', 1:nc-wsize+1, avg, 'b', 1:nc-wsize, avg2, 'g')
More information about the users
mailing list