From: Sean Douglas on
Hey guys I have a moving average code that I asked some advice on before, but i'm still not getting it to work any faster. It is still taking about 10 minutes to run even after adding in a line to preallocate my array. Here is the code I am using on a small example.

a= 20041126 7.11
20041127 2.33
20041128 5.88
20041129 4.67
20041130 4.66
20041201 3.01
20041203 2.58
20041204 1.35


MA=3
n=length(a)
k=n - MA
m=1
Mavg=zeros(1,n+1-MA,1) %attempt to preallocate the array
for q=1:n+1 - MA
j=m:MA+m - 1
Mavg(q)=sum(a(j,2))/MA
m=m+1
end

the actuall data i use is 3000 columns of data and figuring a Moving Average of 150. This data of 8 columns and a Moveing average of 3 is just for an example to ask you guys some advice. I know from before people suggested using conv() and differencing my data and allocating an array. conv() im not quite understanding and i don't know what differencing the data is about, so I am attempting to preallocate an array with this line: Mavg=zeros(1,n+1-MA,1) , but still not working.

Please some help to get me started with makeing this moving average calculate faster.

thank you,
sean