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

3 ビュー (過去 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 Center および File ExchangeDescriptive Statistics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by