Date: Jun 10, 2013 3:24 PM
Author: Bruno Luong
Subject: Re: match matrix to closest values

dpb <none@non.net> wrote in message <kp5433$adc$1@speranza.aioe.org>...
> On 6/9/2013 5:50 PM, Y wrote:

>
> I'd guess could be written w/ bsxfun() but didn't try it...not that it
> would likely perform any better...


bsxfun is much safer in term of memory consumption. It is always preferable method.

Back to the question, there is no need to compare all the pairs. This should do:

h = unique(haystack(:))
val = interp1(h,h,needle,'nearest')

% Bruno