help-octave
[Top][All Lists]
Advanced

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

bsearch in octave


From: Jeff Abrahamson
Subject: bsearch in octave
Date: Fri, 24 Jun 2005 13:00:41 -0400
User-agent: Mutt/1.5.9i

I want to find the last element in a row vector that is less than a
given value.  I want the index of this value.  In C, for example, I'd
use bsearch (binary search), thus the subject on my mail.

I don't see how to do this in octave (besides implementing binary
search).  Did I miss it?  Any pointers?

Thanks much.

For example,

    bsearch([1, 3, 7, 15], 6)  ==> 2
    bsearch([1, 3, 7, 15], 7)  ==> 3
    bsearch([1, 3, 7, 15], 8)  ==> 3

That is, 3 < 6 < 7, but 7 < 7 < 15 and 7 < 8 < 15.  And 3 has index 2,
7 has index 3.

-- 
 Jeff

 Jeff Abrahamson  <http://www.purple.com/jeff/>    +1 215/837-2287
 GPG fingerprint: 1A1A BA95 D082 A558 A276  63C6 16BF 8C4C 0D1D AE4B



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