interp1 using method 'previous' returns an unexpected NaN?

조회 수: 5 (최근 30일)
Marc Cousoulis
Marc Cousoulis 2017년 1월 12일
편집: Stephen23 2017년 1월 12일
x = [1 2 4]; v = [17 100 17]; xq = 1:5; vq = interp1(x,v,xq,'previous');
vq = 17 100 100 17 NaN
Why is vq(5) not equal to 17?

채택된 답변

Stephen23
Stephen23 2017년 1월 12일
편집: Stephen23 2017년 1월 12일
This is clearly explained in the interp1 documentation, in the section "Extrapolation strategy":
  • If you specify the 'pchip' or 'spline' interpolation methods, then the default behavior is 'extrap'.
  • All other interpolation methods return NaN by default for query points outside the domain.
Your query point is outside of the input domain (from 1 to 4), so NaN is the correct and documented output.
As the documentation states, if you want to extrapolate, then you need to specify this:
vq = interp1(x,v,xq,'previous','extrap')

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Interpolation에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by