MATLAB: Determining the intersection of two vectors

intersectline

Below is my working code for a simple program to graph two vectors.
line([0,50],[30,30]); line1 = [0 30 50 30 ];
line([55,55],[15,30]); line2 = [55 15 55 30];
C = intersect(line1,line2)
Below is the visual representation of these two lines:
It is barely visible in the top right corner that these two lines do not intersect. intersect(A,B) however indicates they're intersecting at 30. I assume this is because it treats the vectors as lines which extend forever? Is there any functionality for matlab which would handle only the given space as opposed to infinite length? It should ideally return these lines do not intersect.
Thanks!

Best Answer

The intersect function is a set operation in MATLAB. It looks for the points (elements) that ‘line1’ and ‘line2’ have in common. They both have 30 so that is the correct result.