Getting data values from a plot

Hi Guys,
I want to get (x,y) values from a plot. Say my plot is made of the following points (1,1) (2,3) (4,4) and (5,9). Is there anyway to get the value of y on this plot when x=2.5.
Thanks NS

 採用された回答

Nathan Greco
Nathan Greco 2011 年 7 月 8 日

0 投票

User interpolation
x = [1 2 4 5];
y = [1 3 4 9];
xi = x(1):.01:x(end); %values between x
yi = interp1(x,y,xi);
findyatx = 2.5;
yfound = yi(abs(xi-findyatx)<eps);

3 件のコメント

NS
NS 2011 年 7 月 8 日
Thanks Nathan.
Is this interpolation valid only for integer X and Y values. What about the case of non integer values of x. I am getting the following error.
"??? Error using ==> interp1 at 261
The values of X should be distinct."
Sean de Wolski
Sean de Wolski 2011 年 7 月 8 日
Distinct means no duplicates. Take the mean of any duplicate values. (unique and accumarray will be your friends)
NS
NS 2011 年 7 月 8 日
Works really well. Thanks Nathan

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

その他の回答 (1 件)

Sean de Wolski
Sean de Wolski 2011 年 7 月 8 日

0 投票

You mean fit a line to it and solve?
Sure, use polyfit and polyval.
doc polyfit
doc polyval

3 件のコメント

NS
NS 2011 年 7 月 8 日
Thanks. It works ok. Is there any way to get the best degree for the polynomial automatically. I need to do this for a plot of plots and the curve fitting maybe different for each.
Sean de Wolski
Sean de Wolski 2011 年 7 月 8 日
"Best" is a word you could write a PhD thesis on.
NS
NS 2011 年 7 月 8 日
Hehehehhe....Ok..

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

カテゴリ

ヘルプ センター および 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