How to fix error about interp1?
209 次查看(过去 30 天)
显示 更早的评论
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
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)
回答(2 个)
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.
0 个评论
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.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!