I plot an x , y graph can i ask the programme to tell me the value of y for the value of x i want ? how i can write these at the command window ?
Best Answer
I agree with Jan - it's ambiguous. You already have x, and y since you plotted it, so there's no need to extractanything from the axes (graph) at all. So in that case, I'd just use the x and y which are already available, and if the x is in the x array that you plotted, you can do this:
index = find(x == desiredXValue); % May be multiple indexes, possibly
yDesired = y(index);
Now, if the desired x isnot in your x array, then you can use interp1() to get the interpolated/estimated y value for that x.
‘Spline interpolation using not-a-knot end conditions. The interpolated value at a query point is based on a cubic interpolation of the values at neighboring grid points in each respective dimension.’
It does not appear to be the same as 'cubic'. According to the documentation, 'cubic' is currently the same as 'pchip'.
The two methods do not produce exactly the same results, however with respect to the amplitude of the values in the plot, they only appear to be the same.
Best Answer