Path: news.mathworks.com!newsfeed-00.mathworks.com!NNTP.WPI.EDU!elk.ncren.net!newsflash.concordia.ca!canopus.cc.umanitoba.ca!not-for-mail
From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)
Newsgroups: comp.soft-sys.matlab
Subject: Re: Find nearest index
Date: Tue, 31 Jul 2007 06:18:26 +0000 (UTC)
Organization: National Research Council Canada - Conseil national de rechereches Canada
Lines: 26
Message-ID: <f8mk7i$o4r$1@canopus.cc.umanitoba.ca>
References: <f8mjkc$m3i$1@fred.mathworks.com>
NNTP-Posting-Host: origin.ibd.nrc.ca
X-Trace: canopus.cc.umanitoba.ca 1185862706 24731 192.70.172.160 (31 Jul 2007 06:18:26 GMT)
X-Complaints-To: abuse@cc.umanitoba.ca
NNTP-Posting-Date: Tue, 31 Jul 2007 06:18:26 +0000 (UTC)
Originator: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)
Xref: news.mathworks.com comp.soft-sys.matlab:421801


In article <f8mjkc$m3i$1@fred.mathworks.com>,
Sven  <sven.holcombe@removethis.gmail.com> wrote:

>Given an array of increasing numbers, how do I find the nearest index to another given number?

>Ie,
>myCol = [50 150 200]
>nearestNeigbour(myCol, 40)  % returns 1
>nearestNeigbour(myCol, 65)  % returns 1
>nearestNeigbour(myCol, 130) % returns 2

Hmmm, what about 100? That is, which answer do you want in the
case that something is equidistant between two numbers?

Also, which ordering should be assumed if the input has
complex numbers? Matlab uses two different orderings
for complex numbers; the ordering used for sort() is
different than for several other operations.

Are we allowed to assume that there will be at most one
negative infinity and at most one positive infinity?
And that there will be no NaN's, since NaN's are,
by definition, not numbers and the array was said
to contain numbers?
-- 
  All is vanity.                                       -- Ecclesiastes