|
From: | Bill Denney |
Subject: | Re: bsearch in octave |
Date: | Fri, 24 Jun 2005 13:22:32 -0400 (EDT) |
On Fri, 24 Jun 2005, Jeff Abrahamson 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.
I'd do something like: a = [1,3,7,15]; min(find(a <= 6)) Bill --"This is perfect -- naked ladies, candy, and corporal punishment. All wrapped up in one cautionary tale. What could be more guy?"
-- Jon Scieszka, Guys Read ------------------------------------------------------------- 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 -------------------------------------------------------------
[Prev in Thread] | Current Thread | [Next in Thread] |