Why do I get NaNs when I try interpolating with interp1?
92 views (last 30 days)
Show older comments
I am using interp1 to interpolate my data. But, the function is creating NaNs at the end of my query points (last 2000 points).
interp_co2 = interp1(clean_time_co2, clean_co2, time_common);
I have attached clean_time_co2, clean_co2, time_common, and what my computer has as interp_co2. My original data doesn't have any NaNs, but the interp_co2 does have NaN values, and I don't know why.
Thank you!
0 Comments
Answers (1)
Star Strider
on 7 Oct 2021
It will do that if you atempt to extrapolate without telling interp1 how you want to do it.
Try this —
interp_co2 = interp1(clean_time_co2, clean_co2, time_common, 'linear','extrap');
Choose the appropriate interpolation method. (The default is 'linear' so I assume the same extrapolation method.)
Of course, always be careful about extrapolating, because that assumes knowledge about what the data do beyond the region-of-fit that may not be accurate.
.
2 Comments
See Also
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!