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.

 採用された回答

Star Strider
Star Strider 2021 年 1 月 7 日

0 投票

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 件のコメント

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

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeTime Series Events についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by