如何在Matlab中找到图的x截距 [英] How to find the x-intercept of a plot in Matlab
问题描述
我知道这个问题肯定有一个非常简单的答案,但是我似乎找不到. (猜猜我可能在搜索错误的术语.)
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.)
我正在使用 plot(x,data)函数在Matlab中绘制一些数据.
I am plotting some data in Matlab using the plot(x, data) function.
我想找到直线的x轴截距,即y = 0的点.
I want to find the x-intercept(s) of the line, i.e. the point(s) where y = 0.
在某些情况下, data 向量可能实际上不包含等于零的值,因此,这不仅仅是在 data <中查找元素索引的问题. /em>等于零,然后在 x 向量中找到相应的元素.
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.
就像我说的那样,这是一个非常简单的问题,我认为Matlab中已经有一些内置函数...
Like I said, it's a really simple problem and I'd think there's already some in-built function in Matlab...
谢谢您的帮助.
推荐答案
如果要查找X截距作为围绕X轴的2个最接近点之间的插值,则可以使用INTERP1函数:
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);
如果x
和y
单调增加/减少,它将起作用.
It will work if x
and y
are monotonically increasing/decreasing.
这篇关于如何在Matlab中找到图的x截距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!