How to find the crosspoint of two curve

3 次查看(过去 30 天)
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