getting data from plot ?
古いコメントを表示
I plot an x , y graph can i ask the programme to tell me the value of y for the value of x i want ? how i can write these at the command window ?
1 件のコメント
Nastaran kh
2017 年 11 月 12 日
if you plot, in section tools,basic fitting you can evaluate
採用された回答
その他の回答 (3 件)
The question is not clear. If you plot x versus y, the values are known and therefore the problem has not relation to the plotting. But perhaps you have a Figure file and lost the x and y values. Please explain this by editing the original questions.
Do you want the y values exactly at the position of an x value, or are you interested in x values between two given x values also? In the first case consider, that numerical comparisons are bounded by the numerically limited precision:
x = 0:0.1:1;
find(x == 0.3) % does not find a matching element!
So perhaps this helps:
axes;
x = 0:0.1:pi;
y = sin(x);
plot(x, y);
clear('x', 'y'); % for demonstration only
LineH = get(gca, 'Children');
x = get(LineH, 'XData');
y = get(LineH, 'YData');
xx = 0.724 % Any value
yy = interp1(x, y, xx) % Linear interpolation [EDITED, not "linspace"]
xx2 = x(5); % One exact value
index = find(x == xx2); % Of course this is 5
disp(y(index))
5 件のコメント
lclk psdk
2013 年 9 月 15 日
lclk psdk
2013 年 9 月 15 日
lclk psdk
2013 年 9 月 15 日
Image Analyst
2013 年 9 月 15 日
He's getting the data from the graph itself. It's as if you lost your original data, for example by calling the clear('x') command. If you did that unwise thing, then it's possible to extract your data from the graph, which has, in effect "stored" it.
Ilham Hardy
2013 年 9 月 10 日
h = gcf; %handle of current fig
axObj = get(h, 'Children');
datObj = get(axObj, 'Children');
xdata = get(datObj, 'XData');
ydata = get(datObj, 'YData');
Asimananda Khandual
2018 年 1 月 27 日
Respected Image Analyst gave the best answer; I am just simplifying it with examples.
>> x=1:1:100; >> y=5*x+10; >> yDesired = interp1(x,y, 10)
yDesired =
60
>> xDesired = interp1(y,x, 60)
xDesired =
10
=====================================================================================
>> y=5*x.^2+2*x+10; >> plot(y,x) >> xDesired = interp1(y,x, 60)
xDesired =
2.9630
>> yDesired = interp1(x,y, 10)
yDesired =
530
-----------------HELPFILES---------------
Vq = interp1(X,V,Xq,METHOD) specifies alternate methods.
The default is linear interpolation. Use an empty matrix [] to specify
the default. Available methods are:
'nearest' - nearest neighbor interpolation
'linear' - linear interpolation
'spline' - piecewise cubic spline interpolation (SPLINE)
'pchip' - shape-preserving piecewise cubic interpolation
'cubic' - same as 'pchip'
'v5cubic' - the cubic interpolation from MATLAB 5, which does not
extrapolate and uses 'spline' if X is not equally
spaced.
Vq = interp1(X,V,Xq,METHOD,'extrap') uses the interpolation algorithm
specified by METHOD to perform extrapolation for elements of Xq outside
the interval spanned by X.
Vq = interp1(X,V,Xq,METHOD,EXTRAPVAL) replaces the values outside of the
interval spanned by X with EXTRAPVAL. NaN and 0 are often used for
EXTRAPVAL. The default extrapolation behavior with four input arguments
is 'extrap' for 'spline' and 'pchip' and EXTRAPVAL = NaN (NaN +NaNi for
complex values) for the other methods.
PP = interp1(X,V,METHOD,'pp') will use the interpolation algorithm specified
by METHOD to generate the ppform (piecewise polynomial form) of V. The
method may be any of the above METHOD except for 'v5cubic'. PP may then
be evaluated via PPVAL. PPVAL(PP,Xq) is the same as
interp1(X,V,Xq,METHOD,'extrap').
カテゴリ
ヘルプ センター および File Exchange で Spline Postprocessing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!