using interp1 'nearest' and 1 value is missing

1 vue (au cours des 30 derniers jours)
Roy Azami
Roy Azami le 7 Août 2020
Commenté : Roy Azami le 7 Août 2020
hey,
i have 2 datetime arrays and im trying to find the nearest date and time (prior) from one array to another using interp1
my line of code is:
nearest= interp1(refDatetime, 1:length(refDatetime),expDatetime, 'nearest');
refDateTime:
'03-Feb-2020 09:28:38' '03-Feb-2020 10:49:51' '03-Feb-2020 11:02:04' '03-Feb-2020 11:04:18' '03-Feb-2020 11:17:35' '03-Feb-2020 11:20:28' '03-Feb-2020 11:25:41'
expDatetime:
'03-Feb-2020 11:22:39' '03-Feb-2020 11:28:40'
nearest:
6 NaN
interp1 always gives me NaN for the last exp date time (i run the code with several inputs giving different values for these 2 arrays).
the value i expect is 7 but instead its NaN
any idea what i do wrong?

Réponse acceptée

Walter Roberson
Walter Roberson le 7 Août 2020
nearest= interp1(refDateTime, 1:length(refDateTime),expDateTime, 'nearest', 'extrap')
The interpolation mode you were using, linear interpolation (the default) returns nan for anything outside of the range of the input independent variable; you have to turn on extrapolation.
  1 commentaire
Roy Azami
Roy Azami le 7 Août 2020
Thanks!! saved my life :)

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Interpolation dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by