How do I extract a certain datapoint from a curve?

I would like to extract a specific data point from curves. Attached an example curve. Need to find, when x=14.3, what's the value of y?
Need help to achieve this. Many thanks.

 Accepted Answer

Try this:
x = linspace(0, 100); % Create Vector
y = 25 - 10*sin(2*pi*x/100); % Create Vector
xq = 14.3;
yq = interp1(x, y, xq); % Interpolate To Determine Value
figure
plot(x, y)
hold on
plot(xq, yq, '+r')
hold off
ylim([0 40])
text(xq, yq, sprintf('\\leftarrow y(%.1f) = %.1f', xq, yq), 'HorizontalAlignment','left','VerticalAlignment','middle')
.

4 Comments

Thank you so much, Star Stider.
My task is more complex than certain type of curve. My curves are different patterns. I attached another curve here. I don't know if I need to export the datasets from the curve first, then get the specific datapoint.
My approach should work regardless of the curve.
I created my vectors to demonstrate the approach, and that the code works. Use your own vectors with my code.
Thank you so so much, Star Straider. I tried with my vectors, your code works great.
As always, my pleasure!
Thank you!

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!