Where is the problem with these statements related to function 'interp1' with option 'pchip'?

조회 수: 3 (최근 30일)
When I write this on the workspace I get an error:
x=[0 2 8 5 6 8 9 11 12 14 15];
y=[10*ones(1,6) 10.5 15 50 60 85];
s=x(1):0.01:x(end);
ys=interp1(x,y,s,'pchip');
It indicates that the grid vectors are not strictly monotonic increasing. I don't know what the 'grid vectors' refer to, but I suppose it refers to the vector of nodes, 'x', the vector of y values belonging to those nodes, 'y' and the vector of x values (longer than the vector of nodes) where I want to find the values that the interpolant has. 'x' and 's' are strictly monotonic increasing; 'y' isn't. As 'y' could be the reason why the statements don't work as planned, I tried y=[10.001 10.002 10.003 10.004 10.005 10.006 10.5 15 50 60 85], but that hasn't worked either and I keep getting the same error. Changing 'pchip' for 'linear' doesn't keep the same error message from appearing.

채택된 답변

Walter Roberson
Walter Roberson 2016년 5월 26일
You have
x=[0 2 8 5 6 8 9 11 12 14 15];
That is not monotonically increasing: it has an 8 between the 2 and the 5, and then it has another 8 between the 6 and the 9. Perhaps the first 8 is intended to be a 3.

추가 답변 (1개)

Ricardo Boza Villar
Ricardo Boza Villar 2016년 5월 27일
Oh my, oh my! Thank you

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by