Hie guys, I have done a GUI to plot a graph. Now i would like to get the calue from the graph. Lets say i plot(x,y). I would like to get the value out, for example when x=4, what is the value of y. I know there is a datacursormode, but it only show me the value in the graph. In this case, i would like to get the value in the command window.
Thanks Ean

 채택된 답변

Paulo Silva
Paulo Silva 2011년 2월 15일

0 개 추천

You can retrieve the plotted data, for example:
XData=get(get(gca,'children'),'XData');
YData=get(get(gca,'children'),'YData');
Now if you want to know the y value when x=4 just do
YData(XData==4)

댓글 수: 6

Matt Fig
Matt Fig 2011년 2월 15일
Note that the final line may fail. If you get an empty value for that line, use the INTERP1 function instead.
y_4 = interp1(XData,YData,4);
Ean Soo
Ean Soo 2011년 2월 16일
Hie, the children there is it refers to the axes name?
Matt Fig
Matt Fig 2011년 2월 16일
For example:
x = -4:.1:4;
y = x.^2;
plot(x,y)
XData=get(get(gca,'children'),'XData');
YData=get(get(gca,'children'),'YData');
% Get y value for x=3.33 - NOT a data point.
y_3p33 = interp1(XData,YData,3.33,'spline')
Paulo Silva
Paulo Silva 2011년 2월 16일
Children in that case refers to the Line made by the plot.
Ean Soo
Ean Soo 2011년 2월 16일
Thank You, your code help me a lot.
Nasiru Umar Bagudu
Nasiru Umar Bagudu 2022년 2월 5일
What if i want to get the value of x when y is zero for example?

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

추가 답변 (1개)

Walter Roberson
Walter Roberson 2011년 2월 15일

0 개 추천

You can use a custom datacursormode callback that includes display() in its code.

댓글 수: 1

Ean Soo
Ean Soo 2011년 2월 16일
Erm, is not suitable for me in this case because i would want to recall a very precise value like 12.22. I still working on how to recall that thing. Is just didnt work..

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

카테고리

도움말 센터File Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

태그

질문:

2011년 2월 15일

댓글:

2022년 2월 5일

Community Treasure Hunt

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

Start Hunting!

Translated by