Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: vectorizing challenge
Date: Wed, 20 May 2009 01:30:20 +0000 (UTC)
Organization: Xoran Technologies
Lines: 12
Message-ID: <guvmfc$cif$1@fred.mathworks.com>
References: <guvhl1$qif$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1242783020 12879 172.30.248.37 (20 May 2009 01:30:20 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 20 May 2009 01:30:20 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1440443
Xref: news.mathworks.com comp.soft-sys.matlab:541139


"Heywood " <heywoodj123@yahoo.com> wrote in message <guvhl1$qif$1@fred.mathworks.com>...
> Hi all,
> 
> I'm having a hard time trying to vectorize the following code. Suppose I have a vector of interest V, and a reference vector R which is monotonically increasing (it's actually a cumulative distribution function). Both vectors contain only real numbers, except that I've modified R by tacking on -Inf at the beginning and +Inf at the end (the reason for which is hopefully obvious from the code below).
> 
> For each element of V, I want to find the first element of R that is greater than or equal to it.
------

This one is probably not as efficient as Doug's, but is nice and compact

[dummy,inds] = max(  bsxfun(@ge,R(:),V(:).')   );
Result = R(inds);