interpolate a matrix to fill NaN values.

22 views (last 30 days)
13.5047428571429 13.2392558823529 NaN 14.0492333333333 14.8088030303030 14.9159676470588
13.4900666666667 13.2365308823529 NaN 14.0514133333333 14.8108460606061 14.9227199732620
13.4753904761905 13.2338058823529 NaN 14.0535933333333 14.8128890909091 14.9294722994652
13.4607142857143 13.2310808823529 NaN 14.0557733333333 14.8149321212121 14.9362246256684
13.4460380952381 13.2283558823529 NaN 14.0579533333333 14.8169751515151 14.9429769518717
13.4313619047619 13.2256308823529 NaN 14.0601333333333 14.8190181818182 14.9497292780749
13.4166857142857 13.2229058823529 NaN 14.0623133333333 14.8210612121212 14.9564816042781
13.4020095238095 13.2201808823529 NaN 14.0644933333333 14.8231042424242 14.9632339304813
13.3873333333333 13.2174558823529 NaN 14.0666733333333 14.8251472727273 14.9699862566845
13.3726571428571 13.2147308823529 NaN 14.0688533333333 14.8271903030303 14.9767385828877
13.3579809523810 13.2120058823529 NaN 14.0710333333333 14.8292333333333 14.9834909090909
This is the matrix I have and I want to replace NaN by using interp1. The values represent temperature of each point along the depth.

Accepted Answer

KSSV
KSSV on 3 Dec 2020
Edited: KSSV on 3 Dec 2020
Read about fillmissing.
Or use interp1 as shown:
clc; clear all ;
T = [13.5047428571429 13.2392558823529 NaN 14.0492333333333 14.8088030303030 14.9159676470588
13.4900666666667 13.2365308823529 NaN 14.0514133333333 14.8108460606061 14.9227199732620
13.4753904761905 13.2338058823529 NaN 14.0535933333333 14.8128890909091 14.9294722994652
13.4607142857143 13.2310808823529 NaN 14.0557733333333 14.8149321212121 14.9362246256684
13.4460380952381 13.2283558823529 NaN 14.0579533333333 14.8169751515151 14.9429769518717
13.4313619047619 13.2256308823529 NaN 14.0601333333333 14.8190181818182 14.9497292780749
13.4166857142857 13.2229058823529 NaN 14.0623133333333 14.8210612121212 14.9564816042781
13.4020095238095 13.2201808823529 NaN 14.0644933333333 14.8231042424242 14.9632339304813
13.3873333333333 13.2174558823529 NaN 14.0666733333333 14.8251472727273 14.9699862566845
13.3726571428571 13.2147308823529 NaN 14.0688533333333 14.8271903030303 14.9767385828877
13.3579809523810 13.2120058823529 NaN 14.0710333333333 14.8292333333333 14.9834909090909] ;
[m,n] = size(T) ;
for i = 1:m
x = 1:n ;
y = T(i,:) ;
id = find(isnan(y)) ;
xi = setdiff(x,id) ;
T(i,id) = interp1(xi,y(xi),id) ;
end
  1 Comment
Day Hong Kim
Day Hong Kim on 3 Dec 2020
Thank you for the help! I will try both fillmissing and interp1.

Sign in to comment.

More Answers (0)

Categories

Find more on Interpolation in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!