help-octave
[Top][All Lists]
Advanced

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

Re: bsearch in octave


From: LUK ShunTim
Subject: Re: bsearch in octave
Date: Sat, 25 Jun 2005 21:20:26 +0800
User-agent: Mozilla Thunderbird 1.0.2 (Windows/20050317)

On 2005-06-25 17:35, Geraint Paul Bevan wrote:
LUK ShunTim wrote:

On 2005-06-25 1:00, 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.

[snipped]


This seems to be what you want.


a=[1,3,7,15];
index=find(a>6)(1) - 1


That doesn't find the last matching number. If I understand the question
correctly, in the larger search space

octave> a=[1,3,7,15,4,19];

the answer should be the last number less than or equal to 6, which is 4
in position 5, but

octave> index=find(a>6)(1) - 1
index = 2


The following function works,

function i = bsearch(x,n);
  i = find(x<=n)(end);
end


[snipped]

Thanks for pointing it out. I mis-read the question as finding the index of first element that has a value less than the given value.

And I learn what is a bsearch now; but I don't understand how does "binary" comes in?

Regards,
ST
--



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