Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: find nearest,closest value
Date: Sun, 1 May 2011 01:51:05 +0000 (UTC)
Organization: Queen's University
Lines: 21
Message-ID: <ipiea9$3vr$1@fred.mathworks.com>
References: <gmf901$45e$1@fred.mathworks.com> <gnaitl$5dn$1@fred.mathworks.com> <i8o734$a2d$1@fred.mathworks.com> <i8ofdc$ove$1@fred.mathworks.com> <i8p8t2$p4c$1@fred.mathworks.com> <i8q3g8$o52$1@fred.mathworks.com> <i8qds3$ana$1@fred.mathworks.com> <i8qhm1$cfp$1@fred.mathworks.com> <i8s0rb$la7$1@fred.mathworks.com> <i8s483$i4a$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: www-05-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1304214665 4091 172.30.248.37 (1 May 2011 01:51:05 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sun, 1 May 2011 01:51:05 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 2643899
Xref: news.mathworks.com comp.soft-sys.matlab:724629

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <i8s483$i4a$1@fred.mathworks.com>...
> Sorry: The criteria I stated earlier is flawed, that means the closest L1 point can be even not connected to closest L2 point by any Delaunay simplex.
> 
> Bruno

This is an interesting problem, similar to my present problem:
 Back to the original problem, yet, I do not only attempt to find the closest value from a to b, but also attempt to replace the closest value in a to that in b, and return the index of being replaced elements in a. Notice that if two elements in b corresponds to the same element in a as the common nearest value, then I may want to replace that value in a with the closest or most lefthandside nearest points in b.

For example, 
a=[1, 2, 3, 4, 5, 6];
b=[2.1, 1.9, 3.2];
 Obviously, both 1.9 and 2.2 in b close to 2 in a, but I want to replace 2 with 1.9 as ,1.9 is the nearest point in the leftside of 2. Such that, I attempt to obtain the following new vector and index of elements being replaced:
new_a=[1, 1.9, 3.2, 4, 5, 6];
index_replaced_in_a=[2, 2, 3];

Could you guys figure out a way to do so in a general way? a,b can be vectors or arrays of coordinates set (not so important)...

Thank you very much!

Cheers,
Xiaodong