Mean function of timeseries with NaN
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
dpb
2018-7-16
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Time Series 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!