MATLAB: Fill missing NaN values with Interpolation

interpolatemissing values

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.

Best Answer

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')