Marking the peak of a plot automatically without having to click on it

131 vues (au cours des 30 derniers jours)
Hi,
Is it possible to mark the peak of a plot automatically with a command without having to to mark on each plot.

Réponse acceptée

Star Strider
Star Strider le 29 Août 2012
Modifié(e) : Star Strider le 29 Août 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));
using the text command.
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 commentaire
Kiki
Kiki le 29 Mar 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!

Connectez-vous pour commenter.

Plus de réponses (3)

Wayne King
Wayne King le 29 Août 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 commentaires
Tom
Tom le 29 Août 2012
It should be; can you provide some sample data?
Ilham Hardy
Ilham Hardy le 29 Août 2012
Below link is the 'how-to' display tooltip syntactically..
Happy reading,

Connectez-vous pour commenter.


Ilham Hardy
Ilham Hardy le 29 Août 2012
  4 commentaires
Lisa Justin
Lisa Justin le 29 Août 2012
thanks, but what do you mean by simple TEXT command
Jan
Jan le 29 Août 2012
See "help text" and "doc text".

Connectez-vous pour commenter.


Sergio Yanez-Pagans
Sergio Yanez-Pagans le 28 Mar 2021
You could use my MATLAB File Exchange function:
Hope you find this useful!

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by