How to find the crosspoint of two curve

3 views (last 30 days)
chengxuan yu
chengxuan yu on 28 Nov 2013
Edited: kjetil87 on 28 Nov 2013
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.

Answers (1)

kjetil87
kjetil87 on 28 Nov 2013
Edited: kjetil87 on 28 Nov 2013
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.

Tags

Products

Community Treasure Hunt

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

Start Hunting!