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