n nearest non NaN values

7 ビュー (過去 30 日間)
Maria445
Maria445 2020 年 5 月 19 日
回答済み: Rik 2020 年 5 月 19 日
I have a long time series (T= 150,000) with some NaN values in it, and I need to perform a regression using a rolling window.
That is, at each time t, I need to regress the past 60 non-NaN values on some other vectors of size (60,1). How can I extract the 60 non-NaN values closest (in the past) to t?
For example, if
A = [30 12 14 NaN 2 5 NaN 90 2 4 5 6 2 2 78 45 12 NaN 4];
and, for each t I need at least 4 past non-NaN values, the first regression I will perform will be at t=5, and will have Y = [30 12 14 2], the second regression will be at t=6, and will have Y = [12 14 2 5], and so on

回答 (1 件)

Rik
Rik 2020 年 5 月 19 日
You can use fillmissing:
B=fillmissing(A,'nearest');%replace NaN with nearest non-NaN value

カテゴリ

Help Center および File ExchangeLinear Regression についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by