问题
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