help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How to find the 3 highest peaks in an array? tia sal22


From: Rick T
Subject: How to find the 3 highest peaks in an array? tia sal22
Date: Thu, 3 Mar 2011 00:40:18 -1000

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
reply via email to

[Prev in Thread] Current Thread [Next in Thread]