Marking the peak of a plot automatically without having to click on it
71 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Lisa Justin
el 29 de Ag. de 2012
Respondida: Sergio Yanez-Pagans
el 28 de Mzo. de 2021
Hi,
Is it possible to mark the peak of a plot automatically with a command without having to to mark on each plot.
0 comentarios
Respuesta aceptada
Star Strider
el 29 de Ag. de 2012
Editada: Star Strider
el 29 de Ag. de 2012
If you have the Signal Processing Toobox, I suggest the findpeaks function with two outputs so that you get the value of the function at the peak as well as the index of your x-variable at which the peak occurs.
For example:
[Peak, PeakIdx] = findpeaks(Y);
and the label would then be:
text(x(PeakIdx), Peak, sprintf('Peak = %6.3f', Peak));
To illustrate:
X = [0:0.1:pi]';
Y = sin(X);
[Peak, PeakIdx] = findpeaks(Y);
figure(1)
plot(X, Y)
text(X(PeakIdx), Peak, sprintf('Peak = %6.3f', Peak))
1 comentario
Kiki
el 29 de Mzo. de 2016
Hi
What if I have multiple peaks and I want the apply the label respectively? How should I write the text command?
Thank you!
Más respuestas (3)
Wayne King
el 29 de Ag. de 2012
Do you know the value of the peak?, then yes, it's easy.
x = randn(100,1);
[val,I] = max(x);
plot(x); hold on;
plot(I,val,'r^','markerfacecolor',[1 0 0])
7 comentarios
Ilham Hardy
el 29 de Ag. de 2012
Below link is the 'how-to' display tooltip syntactically..
Happy reading,
Sergio Yanez-Pagans
el 28 de Mzo. de 2021
You could use my MATLAB File Exchange function:
Hope you find this useful!
0 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!