Quick question/explination Re 'movavg'
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Walter Roberson
le 22 Déc 2011
Related material: http://www.mathworks.com/matlabcentral/answers/1190-movavg-function-lead-and-lag-meaning
Réponses (1)
Matt Tearle
le 22 Déc 2011
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 commentaires
Matt Tearle
le 27 Déc 2011
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)
Voir également
Catégories
En savoir plus sur Financial Toolbox dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!