Quick question/explination Re 'movavg'
2 次查看(过去 30 天)
显示 更早的评论
Hi,
I have just created five arrays, four of them using 'movavg' of variang sample lengths, the last array is just the raw data.
>> [mavS1, mavS2] = movavg(LSEtest{7,2}(:,5),5,20,'e');
>> [mavS3, mavS4] = movavg(LSEtest{7,2}(:,5),50,200,'e');
>> mavS0 = LSEtest{7,2}(:,5);
What is confusing me is that they are all the same size, "double 466x1". This should not be correct as my raw data is 466x1 and a movavg of '200' must be no more than 266x1 as there is insufficient data points for the first 200 entries to creat the average. I have looked at the m-files for movavg and filter and I am just not getting it. Could some one please explain so I know which data points I need to ignore/discard.
Regards,
AD
3 个评论
Walter Roberson
2011-12-22
Related material: http://www.mathworks.com/matlabcentral/answers/1190-movavg-function-lead-and-lag-meaning
回答(1 个)
Matt Tearle
2011-12-22
With filter, ignore the first n points. However, you're using the 'e' option, which doesn't actually call filter. It uses the code:
for j = 2:r
a(j) = a(j-1) + alphal*(asset(j) - a(j-1));
end
where alphal is determined by the lead n, and a(1) = asset(1). Hence, the output values are, in fact, legitimately determined for the entire length of the data set. Essentially, the window length goes from the beginning of the data to the current point.
2 个评论
Matt Tearle
2011-12-27
Yeah, "legitimately" was the best word I could think of at the time. I guess what I really meant was "isn't zero padded". That's the big difference between 'e' and the others. You're right that they all return the same sized vectors as the input. With the regular averaging (using filter), the start of the output is essentially what you said: sum/n even though the sum doesn't include n elements (equivalently, the sum includes n values which are padded with zeros when there's fewer than n data points).
A good way to see the difference between 'e' and the others is to try it on some constant data:
n = 100;
x = linspace(0,1,n)';
y = ones(n,1);
[ysl,yst] = movavg(y,5,20,0);
plot(x,y,x,ysl,x,yst)
figure
[ysl,yst] = movavg(y,5,20,'e');
plot(x,y,x,ysl,x,yst)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Financial Toolbox 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!