Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

New to MATLAB?

Finding intersection point of the lines

Asked by Muhammad

Muhammad (view profile)

on 2 Mar 2012
Latest activity Commented on by NIT JAMSHEDPUR

NIT JAMSHEDPUR (view profile)

on 10 Apr 2015 at 10:02

Hi I have data sets for two lines. i.e. x1,y1 and x2,y2. So i can plot the lines using these point data sets. I would like to know the point (x,y)where these lines intersect each other. Please note that i have tried both [x,y]=intersections(x1,y1,x2,y2); and [x,y]=curveintersect(x1,y1,x2,y2);

i would appreciate if you can tell me the exact command for this purpose.


1 Comment


NIT JAMSHEDPUR (view profile)

on 10 Apr 2015 at 10:02

after poltting completed just select data curser from tool bar click where u want to find the coordinates


Muhammad (view profile)


No products are associated with this question.

2 Answers

Answer by Andrei Bobrov

Andrei Bobrov (view profile)

on 5 Mar 2012
data = rand(20,3);
x1 = sort(data(:,2));
x2 = sort(data(:,3));
y = data(:,1);
pp = interp1(x1,y,'linear','pp');
pp2 = interp1(x2,y,'linear','pp');
xx = xx(max(x1(1),x2(1)) <= xx & min(x1(end),x2(end)) >= xx);
func = @(x)ppval(pp,x)-ppval(pp2,x);
xb = xx([true; diff(func(xx) > 0) ~= 0]);
i1 = hankel(1:2,2:numel(xb));
xout = arrayfun(@(z)fzero(func, xb(i1(:,z))), (1:size(i1,2))' )


Andrei Bobrov

Andrei Bobrov (view profile)

Contact us