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

24 vues (au cours des 30 derniers jours)
Emma Reddy
Emma Reddy le 7 Oct 2021
Commenté : Star Strider le 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!

Réponses (1)

Star Strider
Star Strider le 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 commentaires
Emma Reddy
Emma Reddy le 8 Oct 2021
That makes a lot of sense, thank you!
Star Strider
Star Strider le 8 Oct 2021
My pleasure!
(That’s just how the interp# functions work.)
.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Interpolation dans Help Center et File Exchange

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by