Find value of x, from max y (graph)

figure(2);
vel = diff(y)./diff(x);
plot(x(1:end-1), vel)
display(max(findpeaks(vel)))
x(max(findpeaks(vel)));
Trying to find the value of x corresponding to the maximum value of y, for this velocity vs time graph.
displays error due to logical or integer access.

답변 (2개)

Mischa Kim
Mischa Kim 2014년 10월 17일

0 개 추천

Andrew, check out
x = 0:0.1:6;
y = sin(x + 0.5);
vel = diff(y)./diff(x);
plot(x(1:end-1), vel,x(vel == max(vel)),max(vel),'dr')
Michael Haderlein
Michael Haderlein 2014년 10월 17일
편집: Michael Haderlein 2014년 10월 17일

0 개 추천

I'd actually prefer the following:
...
vel = diff(y)./diff(x);
[maxvel,ind]=max(vel);
plot(x(1:end-1),vel,x(ind),maxvel,'or')
If you have a large number of velocities, this one here will be faster. For a small number, it just doesn't matter.

댓글 수: 5

Andrew
Andrew 2014년 10월 17일
displays the circle, but not displaying the x value still
You can just print it in the command window, e.g.
>> x(ind)
ans =
1.1000
Andrew
Andrew 2014년 10월 17일
thank you very much
Andrew
Andrew 2014년 10월 17일
in addition, if just have a graph and i wanted to find the x value from a y value, how would i do it ?
Michael Haderlein
Michael Haderlein 2014년 10월 17일
What do you mean? You can, for instance, use the Data Cursor tool in the menu toolbar. Or you use the handles (plot_handles=get(gca,'children');) of the plots and then extract the x and the y data of the plots (x=get(plot_handles(1),'xdata');).

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

카테고리

도움말 센터File Exchange에서 Line Plots에 대해 자세히 알아보기

태그

질문:

2014년 10월 17일

댓글:

2014년 10월 17일

Community Treasure Hunt

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

Start Hunting!

Translated by