Need a fix for interp1 error

조회 수: 3 (최근 30일)
Chris Swain-Phipps
Chris Swain-Phipps 2022년 6월 27일
댓글: Chris Swain-Phipps 2022년 6월 27일
Hi,
I am trying to use interp1() function on some input data to increase the number of data points I have available to perform more precise checks, my input data is stated to 5 d.p. but ocassionally adjacent values can be identical (i.e. 0.00007, 0.00026, 0.00041, 0.00041, 0.00057...).
Any thoughts on how I still use the interp1 function without my script crashing when identical values are present?
Many Thanks,
Chris

채택된 답변

dpb
dpb 2022년 6월 27일
The simplest is to use
[ux,ia]=unique(x);
vi=interp1(ux,y(ia),v);
This will use the first of the y values for each unique x; you could get more sophisticated and find those values and average them or otherwise set the interpolant value at that value.
Alternatively, I have on occasion found the duplicate locations and adjusted their positions by ux+/-2*eps(ux) to make them just far enough apart that interp1 doesn't complain. This is useful if there is a real discontinuity in the interpolant at the point and it is desired to model it as well.
  댓글 수: 1
Chris Swain-Phipps
Chris Swain-Phipps 2022년 6월 27일
Yep, that did the trick.
Cheers!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Multirate Signal Processing에 대해 자세히 알아보기

태그

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by