how does the function findpeaks work in matlab?
이전 댓글 표시
I use the function findpeaks to detect peak in a vector,it worked as i expected,but I want to understand how does it work,and what the principle it use.
n=0:1:10;
x = [25 8 15 5 6 10 10 3 1 20 7];
[k,v]=findpeaks(x);
plot(n,x,'b');grid;hold on
plot(n(k),v,'r.');
Can anyone can help me?I will be very appreciate for your kindness.
답변 (2개)
Rik
2017년 5월 3일
0 개 추천
pks = findpeaks(data) returns a vector with the local maxima (peaks) of the input signal vector, data. A local peak is a data sample that is either larger than its two neighboring samples or is equal to Inf. Non- Inf signal endpoints are excluded. If a peak is flat, the function returns only the point with the lowest index.
So that's how it works.
댓글 수: 2
yawen kang
2017년 5월 3일
Jan
2017년 5월 3일
@yawen: It seems like you noticed, that the code is not readable. Please edit your comment and use the "{} Code" button for a proper formatting. Thanks.
yawen kang
2017년 5월 3일
댓글 수: 3
Rik
2017년 5월 3일
If you wan't to look into the function itself, type edit findpeaks and you will see the code Matlab uses.
BTW, as this isn't an answer to your question, but a follow up question based on my answer, you shouldn't use the answer option, but comment instead on my answer.
Adam
2017년 5월 3일
What is the relevance of that code anyway? It doesn't even include a call to findpeaks!
Rik
2017년 5월 3일
Skimming this code, it looks like it aims to replicate findpeaks, although this version doesn't return the first index of a plateau, but the middle.
카테고리
도움말 센터 및 File Exchange에서 描述性统计量에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!