把这个写成函数文件的形式
rollingautocorr.m
///////////////////////////////////////以下是rollingautocorr.m的内容////////////////////////////////
function r=rollingautocorr(input,numLags,rollingwindow)
% input=rand(100,1); %这个是测试用的,我自己没有input的数据,就用随机数造了一个序列
%numlags,滞后期,rollingwidow,滚动窗口长度
%numLags=1;
%rollingwindow=60;
for i=1:length(input)-rollingwindow
y=input(i:i+60);
nFFT = 2^(nextpow2(length(y))+1);
F = fft(y-mean(y),nFFT);
F = F.*conj(F);
acf = ifft(F);
acf = acf(1:(numLags+1)); % Retain non-negative lags
acf = acf./acf(1); % Normalize
acf = real(acf);
acf=acf(2);
r(i)=acf;
end
plot(r)
//////////////////////////////////////////////////////////////////////////////////////////////
调用的时候在command windows 里面写 rollingautocorr(y,1,60),这几个参数都可以改,y你要预先设定