How to fix error about interp1?
209 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentar
Torsten
am 23 Okt. 2022
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)
Antworten (2)
dpb
am 23 Okt. 2022
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 Kommentare
Star Strider
am 23 Okt. 2022
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 Kommentare
Siehe auch
Kategorien
Mehr zu Interpolation finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!