Borrar filtros
Borrar filtros

Find value of x, from max y (graph)

2 visualizaciones (últimos 30 días)
Andrew
Andrew el 17 de Oct. de 2014
Comentada: Michael Haderlein el 17 de Oct. de 2014
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.

Respuestas (2)

Mischa Kim
Mischa Kim el 17 de Oct. de 2014
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 el 17 de Oct. de 2014
Editada: Michael Haderlein el 17 de Oct. de 2014
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 comentarios
Andrew
Andrew el 17 de Oct. de 2014
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 el 17 de Oct. de 2014
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');).

Iniciar sesión para comentar.

Categorías

Más información sobre Line Plots en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by