[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: bsearch in octave
From: |
Marcus Vinicius Eiffle Duarte |
Subject: |
Re: bsearch in octave |
Date: |
Fri, 24 Jun 2005 14:08:43 -0300 |
octave:1> x = [10 20 30 40 50 60]
x =
10 20 30 40 50 60
octave:2> idx = find(x<40)
idx =
1 2 3
octave:3> x(idx(end))
ans = 30
octave:4>
On 6/24/05, Jeff Abrahamson <address@hidden> wrote:
> 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
> -------------------------------------------------------------
>
>
-------------------------------------------------------------
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
-------------------------------------------------------------