How to obtain moving average smoothing of daily time series?
조회 수: 4 (최근 30일)
이전 댓글 표시
I have daily time series, how can I obtain seven day and monthly moving averaged time series.
I have tried the smooth command in matlab but it only provides the value and I also need the time.
댓글 수: 0
답변 (1개)
Johannes Hougaard
2020년 9월 14일
I think the function you need is filter - but that requires a numeric input (for which I would use the datenum function)
timeseries = datetime(2020,01,01):datetime(2020,09,11);
dataseries = randn(size(timeseries));
N = 7; % A seven day average (could be altered to any number you'd like)
average_time = datetime(filter(ones(N,1),N,datenum(timeseries),nan(N-1,1)),'ConvertFrom',"datenum"); %the NaN assures that data are not calculated when data are insufficient
average_data = filter(ones(N,1),N,dataseries,nan(N-1,1));
댓글 수: 0
참고 항목
카테고리
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!