How do I replace zero elements of a Time-series with the average of non-zero elements in it's vicinity?

조회 수: 7 (최근 30일)
I have a time-series traffic data which is the average speed of vehicles passing a fixed-point detector in every one-minute. It's possible that when no vehicle pass this decetor in any interval, the resulting speed is zero in this time series. However, from a traffic point of view, traffic states in these point should be considered as if a few vehicles were passing a free road. Therefore, I'm looking for a practical way to replace these zero elements with reasonable values in it's vicinity WITHOUT changing non-zero elements all over the time-series. In other words, I want to replace ONLY zero elements with an interpolation of the values in its vicinity. This means using filter function is not the case because:
1) it will filter all other elemetns
2) it still does not change zero elements to the values of it's vicinity.
Is there any practical function for this purpsose? Or I have to manually go through all these elements?
My time series looks like below:

채택된 답변

Walter Roberson
Walter Roberson 2019년 4월 5일
Change the 0 to nan, and then call John D'Errico's inpaint_nans https://www.mathworks.com/matlabcentral/fileexchange/4551-inpaint_nans

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Descriptive Statistics에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by