Extracting points from a plot that do not appear in the original data

1 view (last 30 days)
I was wondering if it is possible to extract information from a plot that only 'exists' in the plot itself, not the underlying data. For example, in the attached image I would like to extract the data point where the two lines intersect - however this does not exist in the original data - the closet 'real' points plotted in yellow.
I know I could take a ginput and have the user manually click on the intersection point, but was wondering if it is possible to automate this?

Accepted Answer

Adam Danz
Adam Danz on 19 Mar 2019
Edited: Adam Danz on 21 Mar 2019
Here's a demo
% Order is important!
% Line 1 is defined by the first two values. Line 2 is defined by second two values.
x = [5, 6, 5, 6]; % x coordinates of 4 points
y = [4.5, 6.5, 6.5, 4.5]; % y coordinates of 4 points
% Define function that calculates intersection point
getIntersect = @(x,y)[x(1)*y(2)-x(2)*y(1), x(3)*y(4)-x(4)*y(3)] / [y(2)-y(1), y(4)-y(3); -(x(2)-x(1)),-(x(4)-x(3))];
% xyIntersect is a [1 x 2] vector if (x,y) coordinates of intersection.
xyIntersect = getIntersect(x,y);

More Answers (0)


Find more on Visual Exploration in Help Center and File Exchange




Community Treasure Hunt

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

Start Hunting!