Why do I get NaNs when I try interpolating with interp1?

9 views (last 30 days)
Emma Reddy
Emma Reddy on 7 Oct 2021
Commented: Star Strider on 8 Oct 2021
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!

Answers (1)

Star Strider
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.




Community Treasure Hunt

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

Start Hunting!

Translated by