Fill missing NaN values with Interpolation

I have Matlab 2013, and I want to apply spline interpolation in my data matrix with NaN values. Is there any other method which can do this. As fillmissing functon is not available in lower versions.

2 件のコメント

Adam
Adam 2018 年 7 月 12 日
doc spline
doc interp1
Tsehaye Gebreteklie
Tsehaye Gebreteklie 2022 年 4 月 19 日
knnimpute is prefere than spline. you can write the code like this.
clear all;
clc;
Temp = xlsread(A);
Filldata=knnimpute(Temp);

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

 採用された回答

KSSV
KSSV 2018 年 7 月 12 日

5 投票

a = rand(100,1) ;
% put some NaN's
a(randsample(100,20)) = NaN ;
%%interpolate
x = 1:length(a) ;
a(isnan(a)) = interp1(x(~isnan(a)),a(~isnan(a)),x(isnan(a))) ;
plot(x,a,'.r')
hold on
plot(x,a,'b')

1 件のコメント

EMMA POLLARD
EMMA POLLARD 2021 年 2 月 23 日
@KSSV Is there a way to use the above method but omit larger gaps of data? For example if there is a string longer than 5NaN values could it avoid interpolating these sections?
Thanks

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

その他の回答 (1 件)

ZaidiN
ZaidiN 2018 年 7 月 12 日

0 投票

Is this spline interpolation? Secondly this doesnt fill the locations of NaN with interpolated points.

1 件のコメント

Pawan Sharma
Pawan Sharma 2020 年 5 月 12 日
This is liner interpolation. To make it spline interpolation, add spine as a method of interpolation
a(isnan(a)) = interp1(x(~isnan(a)),a(~isnan(a)),x(isnan(a)), 'spline') ;
It do replace NaNs with interpolated values.

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

カテゴリ

ヘルプ センター および File ExchangeInterpolation についてさらに検索

質問済み:

2018 年 7 月 12 日

Community Treasure Hunt

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

Start Hunting!

Translated by