Fill missing NaN values with Interpolation
128 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
ZaidiN
am 12 Jul. 2018
Kommentiert: Tsehaye Gebreteklie
am 19 Apr. 2022
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 Kommentare
Tsehaye Gebreteklie
am 19 Apr. 2022
knnimpute is prefere than spline. you can write the code like this.
clear all;
clc;
Temp = xlsread(A);
Filldata=knnimpute(Temp);
Akzeptierte Antwort
KSSV
am 12 Jul. 2018
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 Kommentar
EMMA POLLARD
am 23 Feb. 2021
@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
Weitere Antworten (1)
ZaidiN
am 12 Jul. 2018
1 Kommentar
Pawan Sharma
am 12 Mai 2020
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.
Siehe auch
Kategorien
Mehr zu Interpolation finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!