Find the intersection point between plot that was made from data and horizontal lane.

Hello, everyone. I post the question here for the first time. So, the question might be not that clear. Sorry about that.
I plot the data set which is 342*2 martix and wanna find the intersection point with certain horizontal lane. In this case, which code should I use?

1 Comment

You can use logical indexing to find the index of the element in 'y' which is equal to 'I_set'. This index will be the x-coordinate of the intersection, and the value of the array 'y' at that point will be the y-coordinate.
But this may not always give the result, because the data y,x1,x2 etc. used to plot the graph are discrete. There might be elements in y that are very close to the value of the horizontal line, but not exactly equal, in which case logical indexing will not give the intersection point.
As a workaround, you can try the function ismembertol(A,B,tol). It returns an array containing logical 1 (true) where the elements of A are within tolerance of the elements in B. Otherwise, the array contains logical 0 (false). Use find(X) on the resultant output to return an array that contains only the indices where ismembertol(A,B,tol) returns logical 1 (i.e. the x-coordinates of your intersection points)
The default value of tol is 1e-6 for single-precision inputs and 1e-12 for double-precision inputs. You'll have to use trial and error by varying the value of tol so that the find function returns exactly as many indices as the actual number of intersection points. It will depend on the number of samples in the data (more the samples, smaller the value of tol
Edit: You can refer the link shared by @KSSV in his answer, which gives a great visualization of the intersects.

Sign in to comment.

Categories

Tags

Asked:

on 14 Jul 2021

Edited:

on 14 Jul 2021

Community Treasure Hunt

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

Start Hunting!