How can I ask matlab to give me the value of y if I input the value of x?

纵然是瞬间 提交于 2019-12-25 03:16:41

问题


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.


回答1:


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');


来源:https://stackoverflow.com/questions/3618067/how-can-i-ask-matlab-to-give-me-the-value-of-y-if-i-input-the-value-of-x

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!