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

89 visualizaciones (últimos 30 días)
Emma Reddy
Emma Reddy el 7 de Oct. de 2021
Comentada: Star Strider el 8 de Oct. de 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!

Respuestas (1)

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

Iniciar sesión para comentar.

Categorías

Más información sobre Interpolation en Help Center y File Exchange.

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by