Path: news.mathworks.com!newsfeed-00.mathworks.com!newsfeed2.dallas1.level3.net!news.level3.com!postnews.google.com!t20g2000yqa.googlegroups.com!not-for-mail
From: Jim Rockford <jim.rockford1@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Find index locations of a set of numbers relative to given vector
Date: Mon, 11 Oct 2010 14:41:25 -0700 (PDT)
Organization: http://groups.google.com
Lines: 23
Message-ID: <7a380b13-9588-4d11-9d9a-72b721525c6f@t20g2000yqa.googlegroups.com>
NNTP-Posting-Host: 192.12.88.17
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
X-Trace: posting.google.com 1286833285 32137 127.0.0.1 (11 Oct 2010 21:41:25 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Mon, 11 Oct 2010 21:41:25 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: t20g2000yqa.googlegroups.com; posting-host=192.12.88.17; posting-account=4Urz8AoAAACdZdE7V_yvznqNgM-aThfn
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.10)
 Gecko/20100914 Firefox/3.6.10 ( .NET CLR 3.5.30729),gzip(gfe)
Xref: news.mathworks.com comp.soft-sys.matlab:677536

This is easy to do in a for-loop, and what I'm asking is whether there
is something quicker.  Given a sorted (increasing values) reference
vector  x, and another vector y containing a bunch of random values,
then identify for each element of y the index of the element of x to
which each value of y is the closest.  If any y value is out of the
range of x then return  0  if  the y value is too small,  and  return
length(x)+1  if it is too large.  (for those who know numerical
recipes this is what the "locate" recipe does).

Example:

x = [1  2  3  4  5  6];  % reference vector
y = [5.8  2.4  6  -1  18  3.9];

The y-value 5.8  falls in the 5th interval of x, so the function would
return 5 for this value.  Etc.

result = [5  2  6  0  7  3];

Any functions out there that handle this?

Thanks,
Jim