如果我输入x的值,我怎么能要求matlab给我y的值? [英] How can I ask matlab to give me the value of y if I input the value of x?
问题描述
我已经有了使用折线图的xy图。让我感到困扰的是,如果我给出x的值,我该如何让matlab给我y的值。也就是说,当我在图中给出x的行时,y的相应值。
我认为你想要做的是内插。
说出你用于绘图的x和y值分别存储在 xData
和 yData
中。
然后,找到一个值 y
,它对应于一个值 x
使用 INTERP1
y = interp1(xData,yData,x);
默认情况下, interp1
线性插值,是,它返回的值就好像图中的点用直线连接。如果你想要更平滑的插值,你可以使用
y = interp1(xData,yData,x,'cubic');
I already have my xy graph using the line graph. What troubles me is how can I ask matlab to give me the value of y if I give the value of x. That is, the corresponding value of y when I give x in the line I have in the graph.
What I think you want to do is interpolation.
Say your x and y values that you used for plotting are stored in xData
and yData
, respectively.
Then, you find a value y
that corresponds to a value x
using INTERP1
y = interp1(xData,yData,x);
By default, interp1
interpolates linearly, that is, it returns the values as if the dots in the plot were connected by straight lines. If you want a smoother interpolation, you'd use
y = interp1(xData,yData,x,'cubic');
这篇关于如果我输入x的值,我怎么能要求matlab给我y的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!