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.

 Respuesta aceptada

Star Strider
Star Strider el 7 de En. de 2021
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 comentarios

Ling Li
Ling Li el 7 de En. de 2021
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.
Ling Li
Ling Li el 8 de En. de 2021
Thank you so so much, Star Straider. I tried with my vectors, your code works great.
As always, my pleasure!
Thank you!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Productos

Etiquetas

Preguntada:

el 6 de En. de 2021

Comentada:

el 8 de En. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by