필터 지우기
필터 지우기

How can I find the peak values of a curve?

조회 수: 16 (최근 30일)
Ashfaq Ahmed
Ashfaq Ahmed 2022년 8월 31일
댓글: Abderrahim. B 2022년 8월 31일
Hi all!
So I have these curves which have several peaks. Can anyone please tell me how can I detect the peaks and put a value to those points? The attached picture is manually created -
Any feedback from you will be highly appreciated! Thank you!

채택된 답변

Abderrahim. B
Abderrahim. B 2022년 8월 31일
Hi!
Use findpeaks for each curve. Put findpeaks function in a for loop together with the plot function.
Demo:
randData = randi(10, 10, 5) ;
for ii = 1: length(randData(1,:))
plot(randData(:,ii))
findpeaks(randData(:,ii), "Annotate","peaks")
hold on
end
Hope this helps
  댓글 수: 2
Ashfaq Ahmed
Ashfaq Ahmed 2022년 8월 31일
Thank you! It helps! How can I use the "text" function to show the values?
Abderrahim. B
Abderrahim. B 2022년 8월 31일
You are welcome.
Try this:
randData = randi(10, 10, 3) ;
for ii = 1: length(randData(1,:))
% plot(randData(:,ii))
[pks,locs] = findpeaks(randData(:,ii), 'Annotate','peaks');
findpeaks(randData(:,ii))
text(locs-0.04,pks+0.4,split(num2str(pks')))
hold on
end
hold off

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

추가 답변 (1개)

Cris LaPierre
Cris LaPierre 2022년 8월 31일
If you are using a live script, I suggest using the Find Local Extrema task. You can see an introduction to this tool in this recent live stream. It will allow you to interactively find the right settings to identify your peaks. If you prefer to do it programmatically, look into the findpeaks function.
Once you have the indices of the peaks, you can use the text function to label them in your plot.
  댓글 수: 1
Ashfaq Ahmed
Ashfaq Ahmed 2022년 8월 31일
Hi Cris! Thank you so much! Will do that!

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

카테고리

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