3
votes

Consider that I have the following sets of values,

Y = [1  23  4  67  89  23  5   12 ]
X = [0  2   4  6   10  14  18  22 ]

I can draw a plot with the basic plot function. Now, from this plot, I want to know what the Y value for X=5. How can I get this data?

You can see, it's not part of my plot points, but something I was to extract from the graph.

Any ideas folks? I'm a bit surprised that there isn't a built in function for this.

2

2 Answers

4
votes

Since plot uses linear interpolation, you should use it as well.

   y = interp1(X,Y,5);
4
votes

The function you are looking for is interp1

For your example, the code would be

 y = interp1(X, Y, 5, 'linear');