smooth.m (400B)
1 % smooth.m y=smooth(x,n0,n1) 2 % 3 % Constructs moving averages of a time series x using the average value 4 % for -n0 years and +n1 years. If n1 doesn't exit, then +/-n0. 5 6 function y=smooth(x,n0,n1); 7 if exist('n1')~=1; n1=n0; end; 8 [T K]=size(x); 9 y=zeros(T,K)*NaN; 10 for i=(1+n0):(length(x)-n1); 11 y(i,:)=zeros(1,K); 12 for j=-n0:n1; 13 y(i,:)=y(i,:)+x(i+j,:); 14 end; 15 end; 16 y=y/(n0+n1+1);