Find position of max value in a graph

130 vues (au cours des 30 derniers jours)
Adam Stemberger
Adam Stemberger le 5 Déc 2019
Modifié(e) : Raj le 5 Déc 2019
how do I find the position (x,y) of the maximum value on a graph?
I'm just has started with matlab so if there is an easy way to do this that I can understand I will be greatfull.
L=0.37;
A=0.008;
m=2.5;
i=2;
lambda=0.2;
r=lambda*L;
w=1800/60*2*pi;
phi=linspace(0,2*pi);
xphi=-lambda*L.*cos(phi)-L.*sqrt(1-lambda^2.*sin(phi).^2)+L+lambda*L;
figure(1)
plot(phi,xphi,'g')
ylabel('sträcka [m]')
xlabel('vinkel [grader]')
title('Position')

Réponses (2)

Walter Roberson
Walter Roberson le 5 Déc 2019
[max_xphi, maxidx] = max(xphi);
phi_at_max_xphi = phi(maxidx);
The maximum is at x = phi_at_max_xphi, y = max_xphi

Raj
Raj le 5 Déc 2019
Modifié(e) : Raj le 5 Déc 2019
Just add this at the end of your code:
[Y, I]=max(xphi);
X_Max=phi(I)
Y_Max=Y
Or do you want max point markup on your plot? In that case use this:
[Y, I]=max(xphi);
X_Max=phi(I)
Y_Max=Y
hold on
scatter(X_Max,Y_Max)
textString = sprintf('(%f, %f)', X_Max, Y_Max);
text(X_Max, Y_Max,textString);

Catégories

En savoir plus sur Graphics Performance dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by