How to fix error about interp1?

조회 수: 209 (최근 30일)
SUNG GOOK YUN
SUNG GOOK YUN 2022년 10월 23일
댓글: Torsten 2022년 10월 23일
Hello,
I have some data and i want to run this code:
Pi=0:10:500;
pi=Pi';
WTEMP=interp1(wdepth(:,1),wtemp(:,1),pi);
It says Sample points must be unique.
wdepth is 273x1 double. / wtemp is 273x1 too.
wdepth have 0,30,50,100,150 values.
how can i fix it??
  댓글 수: 1
Torsten
Torsten 2022년 10월 23일
Is "wdepth" sorted and has unique values ?
x = [0 0 2 3 1];
y = [1 2 3 4 5];
xq = 1.5;
yq = interp1(x,y,xq)
Error using matlab.internal.math.interp1
Sample points must be unique.

Error in interp1 (line 188)
VqLite = matlab.internal.math.interp1(X,V,method,method,Xqcol);

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

답변 (2개)

dpb
dpb 2022년 10월 23일
From the description it appears you have only 5 unique values in wdepth(:,1). As the doc and the error message say, interp1 can accept only unique values for the interpolating variable.
You'll have to pick which set of the unique values you want; one would presume there must be some other variables also in the total dataset (like a set of lat/long coordinates, maybe???) that led to there being multple values at the same value of the one variable.
Perhaps you could use interp2 or interpn instead with the full gridded array.

Star Strider
Star Strider 2022년 10월 23일
It would be helpful to have ‘wtemp’ and ‘wdepth’ to experiment with, as well as a description of what you want to do.
It may only be necessaary to reshape them to create a matrix from them. After that, there are matrix interpolation functions you can use (such as griddedInterpolant) to interpolate specific values.

카테고리

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

태그

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by