How to find a y value given the x on a plot?
4 views (last 30 days)
Show older comments
Elena Dipalma
on 29 May 2021
Commented: Star Strider
on 2 Jun 2021
Hello!
My current problem is I'm trying to achieve a plot like this:

But all I have is the blue plot and the x's of the values I want to scatter plot on the line. I was wondering if there was a way to get the y values from the plot.
I tried idexing the blue signal with che x's, but it gives me an ''index must be positive integers'' error.
Can anyone help me with that?
0 Comments
Accepted Answer
Star Strider
on 29 May 2021
Without your data, an illustration would be something like this —
x = linspace(-5, 5, 50);
y = sinc(x);
xv = 10*rand(3,1)-5 % Arbitrary 'x' Values
yv = interp1(x, y, xv, 'linear') % Corresp[inding 'y' Values
figure
plot(x, y)
grid
hold on
plot(xv, yv, 'p')
hold off
.
2 Comments
Star Strider
on 2 Jun 2021
As alkways, my pleasure!
I appreciate your compliment.
You have a wonderful day, too!
More Answers (0)
See Also
Categories
Find more on Annotations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!