Want to take a section of a curved line between 2 points

조회 수: 1 (최근 30일)
katherine keogh
katherine keogh 2021년 5월 27일
답변: William Rose 2021년 5월 27일
I have an irregular curved line and I want to take a section of it between 2 known points. How might I do this

답변 (1개)

William Rose
William Rose 2021년 5월 27일
interp1(x,y,xq,method) will interpolate in a smooth way. See the help for it here. You tell it the known x's and y's (vectors x,y) and xq, the vector of query x values - where you want to interpolate. For method, try the smooth options and see which you like: 'pchip', cubic', 'makima', or 'spline'. I like 'pchip' and 'makima' because they don't overshoot between points.
x=0:5; y=rand(1,6);
xq=0:0.2:5;
y1=interp1(x,y,xq,'pchip');
y2=interp1(x,y,xq,'cubic');
y3=interp1(x,y,xq,'makima');
y4=interp1(x,y,xq,'spline');
plot(x,y,'k*',xq,y1,'r.-',xq,y2,'g.-',xq,y3,'b.-',xq,y4,'m.-');
legend('raw','pchip','cubic','makima','spline');
Example above: interpolation with different methods.

카테고리

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