Matlab – How to find the x-intercept of a plot in Matlab

graphinterceptMATLABplot

I know there must be a really simple answer to this question, but I just can't seem to find it. (Guess I'm probably Googling the wrong terms.)

I am plotting some data in Matlab using the plot(x, data) function.

I want to find the x-intercept(s) of the line, i.e. the point(s) where y = 0.

In some cases, it may be that the data vector doesn't actually contain values equal to zero, so it's not just a matter of finding the indexes of the elements in data which are equal to zero, and then finding the corresponding elements in the x vector.

Like I said, it's a really simple problem and I'd think there's already some in-built function in Matlab…

Thank you for your help.

Best Answer

If you want to find X-intercept as interpolate between 2 closest points around X axes you can use INTERP1 function:

x0 = interp1(y,x,0);

It will work if x and y are monotonically increasing/decreasing.