|
From: | Rick T |
Subject: | Re: How to find the 3 highest peaks in an array? tia sal22 |
Date: | Thu, 3 Mar 2011 08:03:54 -1000 |
Rick,
You could use sortrows on a matrix of the indexes and their corresponding peak values, then find the peak values > 5 and take the first three, or less than three if there are no matching peaks.
You might also look at peakdetect, see http://www.billauer.co.il/peakdet.html
Bill Krekeler
From: address@hidden [mailto:address@hidden] On Behalf Of Rick T
Sent: Thursday, March 03, 2011 4:40 AM
To: address@hidden
Subject: How to find the 3 highest peaks in an array? tia sal22
How to find the 3 highest peaks in an array tia sal22
Greetings All
I have some example code that will find the min and max
peaks of an array. How would I go about adjusting the
code to find the 3 highest peaks over the value 5?
example code:
a = [1 2 2 3 2 1 1 5 1 17 17 17 15 20 1 4 5 2 5 7 4 7];
p = 1:length(a);
b = diff([inf a])~=0;
aa = a(b); pp = p(b);
maxima = pp(find(aa>[aa(2:end) inf] & aa>[inf aa(1:end-1)]))
a_valmax=a(maxima(:,:))
minima = pp(find(aa<[aa(2:end) -inf] & aa<[-inf aa(1:end-1)]))
a_valmin=a(minima(:,:))
tia sal22
[Prev in Thread] | Current Thread | [Next in Thread] |