Mean function of timeseries with NaN
1 view (last 30 days)
Show older comments
First I define a simple timeseries with NaN value:
x=timeseries([5 5 5 5 NaN],[1 2.5 3.8 4 4.2]);
Then I expect that mean value (time weighted) would be 5.
But the result of
mean(x,'Weighting','time') is 5.9414
Why?
0 Comments
Answers (1)
dpb
on 16 Jul 2018
MATLAB determines weighting by:
Attaching a weighting to each time value, depending on its order, as follows:
First time point — The duration of the first time interval (t(2) - t(1)).
Time point that is neither the first nor last time point — The duration between the midpoint of the previous time interval to the midpoint of the subsequent time interval ((t(k + 1) - t(k))/2 + (t(k) - t(k - 1))/2).
Last time point — The duration of the last time interval (t(end) - t(end - 1)).
Normalizing the weighting for each time by dividing each weighting by the mean of all weightings.
I didn't try to compute what those would be for your time vector, but the net result appears to result in 5.9 for the weighted answer.
See Also
Categories
Find more on Time Series in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!