getting data from plot ?

조회 수: 646 (최근 30일)
lclk psdk
lclk psdk 2013년 9월 10일
댓글: Image Analyst 2023년 4월 21일
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
Nastaran kh 2017년 11월 12일
if you plot, in section tools,basic fitting you can evaluate

댓글을 달려면 로그인하십시오.

채택된 답변

Image Analyst
Image Analyst 2013년 9월 10일
I agree with Jan - it's ambiguous. You already have x, and y since you plotted it, so there's no need to extract anything from the axes (graph) at all. So in that case, I'd just use the x and y which are already available, and if the x is in the x array that you plotted, you can do this:
index = find(x == desiredXValue); % May be multiple indexes, possibly
yDesired = y(index);
Now, if the desired x is not in your x array, then you can use interp1() to get the interpolated/estimated y value for that x.
yDesired = interp1(x,y, desiredXValue);
  댓글 수: 11
DEEPIKA E
DEEPIKA E 2023년 4월 21일
Thank you
Image Analyst
Image Analyst 2023년 4월 21일
change is your y so
y = ((Temperature-Ti)/(Tf-Ti))*100
and x is time according to your plot(time, change) call. By the way, don't use time, or any other built-in function name as your variable name because it could lead to confusion and errors. And don't call one variable Time and another time - that's just downright confusing! But anyway, I can't figure out how your y depends on x. Can you give me an equation where y is a function of x? If you want Temperature as a function of change, it's simply
Temperature = (change/100) * (Tf - Ti) + Ti

댓글을 달려면 로그인하십시오.

추가 답변 (3개)

Jan
Jan 2013년 9월 10일
편집: Jan 2013년 9월 10일
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
Image Analyst
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.
lclk psdk
lclk psdk 2013년 9월 16일
편집: lclk psdk 2013년 9월 16일
thank u very much............i am so happy to know such helpful men like u , Jan Simon and Ilham Hardy

댓글을 달려면 로그인하십시오.


Ilham Hardy
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');
  댓글 수: 1
lclk psdk
lclk psdk 2013년 9월 15일
thanks alot

댓글을 달려면 로그인하십시오.


Asimananda Khandual
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').

카테고리

Help CenterFile Exchange에서 Interpolation에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by