Cubic spline interpolation in interp1 doesn't remove NaN

4 ビュー (過去 30 日間)
BB
BB 2021 年 6 月 10 日
回答済み: Steven Lord 2021 年 6 月 10 日
I have functional near-infrared spectroscopy timeseries data which sometimes contain NaNs and/or infinite values in some channels.
Baed on literature, spline interpolation seems to be the method of choice to replace these.
I use interp1 as follows:
Y.hbo(isnan(Y.hbo)) = interp1(find(~isnan(Y.hbo)), Y.hbo(~isnan(Y.hbo)), find(isnan(Y.hbo)), 'spline');
Y ist the structure containing the different hemoglobine signals, with rows indicating sample points and columns containing channels'data. (I attached the mat file.)
NaNs are replaced, e.g., with method 'nearest', 'linear', or 'pchip'. Only 'spline' doesn't replace any NaN.
Any idea what is going wrong?
  2 件のコメント
Mathieu NOE
Mathieu NOE 2021 年 6 月 10 日
hello
which matlab release are you using
I do remember that in older versions, interp1 with spline method was not able to cope with NaN values
that may have been changed as my doc of R2020b does not speak about this limitation;
BB
BB 2021 年 6 月 10 日
Hi Mathieu,
thank you for your fast reply!
I am using Matlab R2020a, so that might indeed be the problem.
I will check this out as soon as possible.
The only thing that speaks against this assumption is the fact, that we inserted NaNs in the example functions given in the Documention and spline worked with it.

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2021 年 6 月 10 日
Y.hbo is 3781 by 24. You are using logical indexing on it, which is going to give you a column vector result in which all of the columns are mixed together. You then ask to do interpolation on all of that at the same time. This is not going to give you the kinds of answers that you want. Consider that if you have a NaN first thing in a column, you would be interpolating from a different column.
You should be interpolating channel by channel. And because NaN could occur at edges, you should specify extrapolation.
  1 件のコメント
BB
BB 2021 年 6 月 10 日
Thank you! That's it! You saved me in several ways!!!!

サインインしてコメントする。

その他の回答 (1 件)

Steven Lord
Steven Lord 2021 年 6 月 10 日
The fillmissing function offers several methods to use in filling in the missing data (NaN in the case of your numeric data.) One of those options is 'spline'.

カテゴリ

Help Center および File ExchangeSpline Postprocessing についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by