How to find the crosspoint of two curve

조회 수: 3 (최근 30일)
chengxuan yu
chengxuan yu 2013년 11월 28일
편집: kjetil87 2013년 11월 28일
I have a array below,[-0.1227 0.0581 0.0733 -0.1087 -0.1375 0.1031 0.1839 -0.0309],now I use the function of 'spline' get the picture in attachment, How can I get the cross point of green line and the black line? The black line also is x_axis.

답변 (1개)

kjetil87
kjetil87 2013년 11월 28일
편집: kjetil87 2013년 11월 28일
If i have done this correctly this should give you the first point in yy before each zero crossing.
y=[-0.1227 0.0581 0.0733 -0.1087 -0.1375 0.1031 0.1839 -0.0309];
x=1:numel(y);
xx=1:0.01:x(end);
yy=spline(x,y,xx);
preCrossIdx=find((yy(1:end-1)<0 & yy(2:end)>0) | (yy(1:end-1)>0 & yy(2:end)<0) );
figure;plot(yy,'x');hold on;plot(1:numel(yy),0,'black');
dummy=nan(size(yy));
dummy(preCrossIdx)=yy(preCrossIdx);
plot(dummy,'rx');
To figure out if the "next index of yy" is closer to zero ,you could just check which one has the closest abs value to zero. The exact crosspoint is a bit more tricky, but a smaller spacing in xx=1:spacing:numel(x) , will give a better approximation.

카테고리

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

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by