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

조회 수: 49 (최근 30일)
Hi,
Is it possible to mark the peak of a plot automatically with a command without having to to mark on each plot.

채택된 답변

Star Strider
Star Strider 2012년 8월 29일
편집: Star Strider 2012년 8월 29일
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
Kiki
Kiki 2016년 3월 29일
Hi
What if I have multiple peaks and I want the apply the label respectively? How should I write the text command?
Thank you!

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

추가 답변 (3개)

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

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


Ilham Hardy
Ilham Hardy 2012년 8월 29일
  댓글 수: 4
Lisa Justin
Lisa Justin 2012년 8월 29일
thanks, but what do you mean by simple TEXT command
Jan
Jan 2012년 8월 29일
See "help text" and "doc text".

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


Sergio Yanez-Pagans
Sergio Yanez-Pagans 2021년 3월 28일
You could use my MATLAB File Exchange function:
Hope you find this useful!

카테고리

Help CenterFile Exchange에서 Descriptive Statistics에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by