[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Finding peaks/max in a graph
From: |
Thomas Shores |
Subject: |
Re: Finding peaks/max in a graph |
Date: |
Mon, 05 Apr 2004 11:33:21 -0500 |
Hmmm. Worked fine for me. And if you want a row/column independent
version, see below.
octave:67> a = [1 2 3 4 5 4 3 2 1 2 3 2 1]';
octave:68> peaks = find([a(2:n,1)-a(1:n-1,1) < 0;1] &
[1;a(1:n-1,1)-a(2:n,1)<0])
peaks =
5
11
octave:69> find(diff(a(1:n-1))>0 & diff(a(2:n))<0)+1
ans =
5
11
On Mon, 2004-04-05 at 10:22, edA-qa mort-ora-y wrote:
> David Bateman wrote:
> > A for-loop is not the way to go about this. Consider the code fragment
> > n = 9
> > a = [1 2 3 4 5 4 3 2 1]';
> > peaks = find([a(2:n,1) - a(1:n-1,1) < 0; 1] & [1; a(1:n-1,1) - a(2:n,1) <
> > 0]);
> > that will find all indexes of the peaks in the data in a single statement
>
> If you set
> a = [1 2 3 4 5 4 3 2 1 2 3 2 1]';
> Peaks will only find 5, not the 3 as well. I will see if somehow,
> however, I can modify my code not to use a for-loop, rather to use a
> similar notation to above.
-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.
Octave's home on the web: http://www.octave.org
How to fund new projects: http://www.octave.org/funding.html
Subscription information: http://www.octave.org/archive.html
-------------------------------------------------------------