注意,我觉得你的问题不是滚动预测,而是不断的把数据的首部分扔掉,而滚动的意思是循环移动。
但不影响解决问题,假设你的被调用的函数是求均值mean函数,代码如下。
x=[3 2 1 3 2]
result = [];
for i=1:length(x)
%调用函数
temp=mean(x);
%将函数返回值放到result中
result=[result temp(1)]
%将x的第一个数扔掉。
x(1)=[];
end
运行结果,把每次循环中的result都显示出来了
result =
2.2000
result =
2.2000 2.0000
result =
2.2000 2.0000 2.0000
result =
2.2000 2.0000 2.0000 2.5000
result =
2.2000 2.0000 2.0000 2.5000 2.0000