help-octave
[Top][All Lists]
Advanced

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

## Re: Finding peaks/max in a graph

 From: David Bateman Subject: Re: Finding peaks/max in a graph Date: Mon, 5 Apr 2004 18:13:06 +0200 User-agent: Mutt/1.4.1i

```According to edA-qa mort-ora-y <address@hidden> (on 04/05/04):
> 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.

Bzzzzzzz wrong....

octave:1> a = [1 2 3 4 5 4 3 2 1 2 3 2 1]';
octave:2> n = length(a);
octave:3> 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:4> a(peaks)
ans =

5
3

D.

--
David Bateman                                address@hidden
Motorola CRM                                 +33 1 69 35 48 04 (Ph)
Parc Les Algorithmes, Commune de St Aubin    +33 1 69 35 77 01 (Fax)
91193 Gif-Sur-Yvette FRANCE

The information contained in this communication has been classified as:

[x] General Business Information
[ ] Motorola Internal Use Only
[ ] Motorola Confidential Proprietary

-------------------------------------------------------------
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
-------------------------------------------------------------

```

reply via email to

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