http://www.mathworks.com/matlabcentral/newsreader/view_thread/243878
MATLAB Central Newsreader  find nearest,closest value
Feed for thread: find nearest,closest value
enus
©19942014 by MathWorks, Inc.
webmaster@mathworks.com
MATLAB Central Newsreader
http://blogs.law.harvard.edu/tech/rss
60
MathWorks
http://www.mathworks.com/images/membrane_icon.gif

Mon, 16 Feb 2009 02:27:01 +0000
Re: find nearest,closest value
http://www.mathworks.com/matlabcentral/newsreader/view_thread/243878#628475
Roger Stafford
"megha bhatt" <mubhatt19@yahoo.co.in> wrote in message <gmf901$45e$1@fred.mathworks.com>...<br>
> Hi,<br>
> I have two vectors a & b and I want to look for closest value of vector b in vector a one by one. How to find it?<br>
<br>
I put your problem aside ten days ago to look at and temporarily forgot about it. Sorry for the delay. I interpret your question to mean that for each element of vector 'a' you seek the nearest element of 'b' in terms of absolute difference. The following assumes that 'a' and 'b' are row vectors and that all the elements of 'a' are finite. It obtains the two row vectors 'd' and 'ib' of the same length as 'a'. Each element of 'd' is the absolute difference between the corresponding element of 'a' and the nearest element of 'b'. Each element of 'ib' is the index with respect to the 'b' vector of that corresponding nearest 'b' element.<br>
<br>
m = size(a,1); n = size(b,1);<br>
[c,p] = sort([a,b]);<br>
q = 1:m+n; q(p) = q;<br>
t = cumsum(p>m);<br>
r = 1:n; r(t(q(m+1:m+n))) = r;<br>
s = t(q(1:m));<br>
id = r(max(s,1));<br>
iu = r(min(s+1,n));<br>
[d,it] = min([abs(ab(id));abs(b(iu)a)]);<br>
ib = id+(it1).*(iuid);<br>
<br>
It is possible to write a somewhat shorter forloop code for this in which a search is made for each element of 'a' for the nearest element of 'b' using the 'min' function, but that would be an order m*n algorithm as opposed to the above order (m+n)*log(m+n) algorithm (due principally to the 'sort' operation on [a,b].) For large m and n, the sort method is therefore considerably faster.<br>
<br>
Roger Stafford

Mon, 16 Feb 2009 03:49:02 +0000
Re: find nearest,closest value
http://www.mathworks.com/matlabcentral/newsreader/view_thread/243878#628492
Shaun
m = size(a,2); n = size(b,2); ??

Mon, 16 Feb 2009 06:10:04 +0000
Re: find nearest,closest value
http://www.mathworks.com/matlabcentral/newsreader/view_thread/243878#628520
Roger Stafford
"Shaun" <s@s.com> wrote in message <gnanne$b6m$1@fred.mathworks.com>...<br>
> m = size(a,2); n = size(b,2); ??<br>
<br>
You're quite right Shaun. It should be the way you have it written. I copied that line in haste at the last moment and made a mistake in doing so. I had tested this code snippet starting with defined m and n used in generating random 'a' and 'b' and almost left the creation of 'm' and 'n' out of the final version to be put in this thread. Thanks for pointing that out.<br>
<br>
Roger Stafford

Thu, 05 Feb 2009 17:52:01 +0000
find nearest,closest value
http://www.mathworks.com/matlabcentral/newsreader/view_thread/243878#626435
megha bhatt
Hi,<br>
I have two vectors a & b and I want to look for closest value of vector b in vector a one by one. How to find it?

Thu, 05 Feb 2009 17:58:22 +0000
Re: find nearest,closest value
http://www.mathworks.com/matlabcentral/newsreader/view_thread/243878#626436
dpb
megha bhatt wrote:<br>
> Hi,<br>
> I have two vectors a & b and I want to look for closest value of<br>
> vector b in vector a one by one. How to find it?<br>
<br>
doc interp1<br>
<br>


Thu, 22 Oct 2009 00:57:20 +0000
Re: find nearest,closest value
http://www.mathworks.com/matlabcentral/newsreader/view_thread/243878#688839
Matlab Matlab
That's some amazing code, Roger. Thank you for contributing it. Is it a wellknown algorithm, or did you figure it out?<br>
<br>
What's the purpose of the following line:<br>
> r = 1:n; r(t(q(m+1:m+n))) = r;<br>
I can't think of a case where it won't end up the same as just r=1:n;<br>
<br>
Thank you.

Fri, 08 Oct 2010 22:48:04 +0000
Re: find nearest,closest value
http://www.mathworks.com/matlabcentral/newsreader/view_thread/243878#786382
Harry Commin
This is brilliant code. Is there a simple way to extend it for comparison of vectors?<br>
<br>
That is, given two matrices, A and B (where size(A,1) == size(B,1)), find the columns of B that have least (sum of) elementbyelement absolute differences with each of the columns of A.<br>
<br>
I'll have a think about it and post whatever I come up with (but it won't be anything like as elegant as the solution for scalars posted above).

Sat, 09 Oct 2010 01:10:04 +0000
Re: find nearest,closest value
http://www.mathworks.com/matlabcentral/newsreader/view_thread/243878#786392
Roger Stafford
"Harry Commin" <hmc05_remove_this_@ic.ac.uk> wrote in message <i8o734$a2d$1@fred.mathworks.com>...<br>
> ......<br>
> That is, given two matrices, A and B (where size(A,1) == size(B,1)), find the columns of B that have least (sum of) elementbyelement absolute differences with each of the columns of A.<br>
> <br>
> I'll have a think about it and post whatever I come up with (but it won't be anything like as elegant as the solution for scalars posted above).<br>
       <br>
The following should solve your problem:<br>
<br>
C = zeros(2,size(A,2));<br>
for p = 1:size(A,2)<br>
[m,q] = min(sum(abs(bsxfun(@minus,B,A(:,p))),1));<br>
C(:,p) = [m;q];<br>
end<br>
<br>
In each column of C corresponding to a column of A the top element is equal to the least sum of absolute differences of that A column with the various columns of B and the bottom element is the corresponding B column index.<br>
<br>
Unfortunately this algorithm is order(size(A,2)*size(B,1)*size(B,2)). It has to do that many subtractions, absolute values, and additions. Therefore for large matrices it will be slow. I could not think of any analog to the sorting trick for single dimensional vectors which would reduce this.<br>
<br>
Roger Stafford

Sat, 09 Oct 2010 08:25:06 +0000
Re: find nearest,closest value
http://www.mathworks.com/matlabcentral/newsreader/view_thread/243878#786426
Bruno Luong
Delaunay triangulation is usually the best method to find nearest vector<br>
<br>
Look ate TRISEARCH(), DELAUNAY() on older Matlab version and TriScatteredInterp class on newer version.<br>
<br>
Bruno

Sat, 09 Oct 2010 15:59:04 +0000
Re: find nearest,closest value
http://www.mathworks.com/matlabcentral/newsreader/view_thread/243878#786473
Roger Stafford
"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <i8p8t2$p4c$1@fred.mathworks.com>...<br>
> Delaunay triangulation is usually the best method to find nearest vector<br>
> <br>
> Look ate TRISEARCH(), DELAUNAY() on older Matlab version and TriScatteredInterp class on newer version.<br>
> <br>
> Bruno<br>
           <br>
Hi, Bruno. That sounds like an excellent idea. However, the poster, Harry, stated a criterion that apparently amounts to an L1 metric, not L2. Are delaunay and TriScatteredInterp amenable to such a metric? The idea of having a circumscribed circle containing no data points sounds very L2 to me. Very likely he could be persuaded to switch to L2 if it results in better algorithm performance.<br>
<br>
Roger Stafford

Sat, 09 Oct 2010 18:56:04 +0000
Re: find nearest,closest value
http://www.mathworks.com/matlabcentral/newsreader/view_thread/243878#786496
Bruno Luong
"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <i8q3g8$o52$1@fred.mathworks.com>...<br>
> "Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <i8p8t2$p4c$1@fred.mathworks.com>...<br>
> > Delaunay triangulation is usually the best method to find nearest vector<br>
> > <br>
> > Look ate TRISEARCH(), DELAUNAY() on older Matlab version and TriScatteredInterp class on newer version.<br>
> > <br>
> > Bruno<br>
>            <br>
> Hi, Bruno. That sounds like an excellent idea. However, the poster, Harry, stated a criterion that apparently amounts to an L1 metric, not L2. Are delaunay and TriScatteredInterp amenable to such a metric? The idea of having a circumscribed circle containing no data points sounds very L2 to me. Very likely he could be persuaded to switch to L2 if it results in better algorithm performance.<br>
> <br>
> Roger Stafford<br>
<br>
Hi Roger, you are right, I did not read carefully. Matlab Delaunay supposes L2 metric (I don't think user is allowed to change). L1 Delaunay seems to be very nasty problem.<br>
<br>
Bruno

Sat, 09 Oct 2010 20:01:05 +0000
Re: find nearest,closest value
http://www.mathworks.com/matlabcentral/newsreader/view_thread/243878#786511
Bruno Luong
Thinking about a little more, even if Delaunay can't be used directly to find L1closest point,it is clearly the candidate points are the those who are connected with the L2closest point by a (L2) Delaunay simplex. This property can be used to reduce the search by computing the L1 distance to few candidates points for a given input points.<br>
<br>
Bruno

Sun, 10 Oct 2010 09:26:03 +0000
Re: find nearest,closest value
http://www.mathworks.com/matlabcentral/newsreader/view_thread/243878#786572
Bruno Luong
I still need to check whereas the criteria for candidate points works when the points outside the convex hull. But here is what I have in mind:<br>
<br>
%% Data<br>
ndim = 2;<br>
nA = 1e2;<br>
nB = 1e4;<br>
A = randn(nA,ndim);<br>
B = 1.2*(randn(nB,ndim));<br>
<br>
% Engine: Find the nearest point in A to every point of B<br>
fprintf('L1 nearest started...\n');<br>
T = delaunayn(A);<br>
L2nearest = dsearch(A(:,1),A(:,2),T,B(:,1),B(:,2));<br>
<br>
% Delaunay's connectivity matrix<br>
C = sparse([],[],[],nA,nA); % == 0<br>
for j = 1:ndim+1<br>
C = C + sparse(repmat(T(:,j),1,ndim+1),T,1,nA,nA);<br>
end<br>
C = logical(C);<br>
<br>
% Candidate matrix (nA x nB)<br>
C = C(:,L2nearest);<br>
<br>
% Compute L1 distances<br>
[iA iB] = find(C);<br>
l1 = sum(abs(A(iA,:)B(iB,:)),2);<br>
% We put the inverse of distance to discard zeroelements of sparse matrix<br>
invL1 = sparse(iA,iB,1./l1,nA,nB);<br>
% max 1/L1 reaches at where min L1 reaches!<br>
[m L1nearest] = max(invL1, [], 1);<br>
L1min = 1./m;<br>
fprintf('L1 nearest done\n');<br>
<br>
%%<br>
fprintf('Graphic output...\n');<br>
Color = lines(64);<br>
ncl = size(Color,1);<br>
figure(1);<br>
clf;<br>
hold on<br>
for iB=1:nB<br>
k = L1nearest(iB);<br>
cl = Color(mod(k1,ncl)+1,:);<br>
plot(B(iB,1),B(iB,2),'.','Color',cl);<br>
end<br>
for iA=1:nA<br>
k = iA;<br>
cl = Color(mod(k1,ncl)+1,:);<br>
plot(A(iA,1),A(iA,2),'o','Color',cl);<br>
end<br>
axis equal<br>
title('L1 nearest')<br>
<br>
% Bruno

Sun, 10 Oct 2010 10:24:03 +0000
Re: find nearest,closest value
http://www.mathworks.com/matlabcentral/newsreader/view_thread/243878#786575
Bruno Luong
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.<br>
<br>
Bruno

Sun, 01 May 2011 01:51:05 +0000
Re: find nearest,closest value
http://www.mathworks.com/matlabcentral/newsreader/view_thread/243878#833849
Xiaodong
"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <i8s483$i4a$1@fred.mathworks.com>...<br>
> 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.<br>
> <br>
> Bruno<br>
<br>
This is an interesting problem, similar to my present problem:<br>
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.<br>
<br>
For example, <br>
a=[1, 2, 3, 4, 5, 6];<br>
b=[2.1, 1.9, 3.2];<br>
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:<br>
new_a=[1, 1.9, 3.2, 4, 5, 6];<br>
index_replaced_in_a=[2, 2, 3];<br>
<br>
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)...<br>
<br>
Thank you very much!<br>
<br>
Cheers,<br>
Xiaodong

Sun, 01 May 2011 04:10:47 +0000
Re: find nearest,closest value
http://www.mathworks.com/matlabcentral/newsreader/view_thread/243878#833855
ImageAnalyst
On Apr 30, 9:51 pm, "Xiaodong " <e20...@gmail.com> wrote:<br>
> "Bruno Luong" <b.lu...@fogale.findmycountry> wrote in message <i8s483$i4...@fred.mathworks.com>...<br>
> > 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.<br>
><br>
> > Bruno<br>
><br>
> This is an interesting problem, similar to my present problem:<br>
> 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.<br>
><br>
> For example,<br>
> a=[1, 2, 3, 4, 5, 6];<br>
> b=[2.1, 1.9, 3.2];<br>
> 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:<br>
> new_a=[1, 1.9, 3.2, 4, 5, 6];<br>
> index_replaced_in_a=[2, 2, 3];<br>
><br>
> 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)...<br>
><br>
> Thank you very much!<br>
><br>
> Cheers,<br>
> Xiaodong<br>
<br>
<br>
Why did the 3 also get replaced? Since the 3 got replaced by 3.2, why<br>
didn't 4, 5, and 6 also get replaced by 3.2? Why didn't the 1 get<br>
replaced by 1.9 also? 1.9 was the closest value in b to the 1 in a.<br>
Is there some greatest difference, where you don't replace if the<br>
difference is too great?

Sun, 01 May 2011 05:27:05 +0000
Re: find nearest,closest value
http://www.mathworks.com/matlabcentral/newsreader/view_thread/243878#833858
Roger Stafford
"Xiaodong" wrote in message <ipiea9$3vr$1@fred.mathworks.com>...<br>
> This is an interesting problem, similar to my present problem:<br>
> 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.<br>
> <br>
> For example, <br>
> a=[1, 2, 3, 4, 5, 6];<br>
> b=[2.1, 1.9, 3.2];<br>
> 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:<br>
> new_a=[1, 1.9, 3.2, 4, 5, 6];<br>
> index_replaced_in_a=[2, 2, 3];<br>
> <br>
> 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)...<br>
> <br>
> Thank you very much!<br>
> <br>
> Cheers,<br>
> Xiaodong<br>
        <br>
To replace elements of vector 'a' by those closest in 'b' in the problem of the original posting (5 Feb 2009) in this thread, just do:<br>
<br>
a = b(ib);<br>
<br>
using the 'ib' index derived in the code of 16 Feb 2009 (as corrected by Shaun) and I believe the index in 'ib' would be the index vector you speak of.<br>
<br>
However, this is not in agreement with your example where the above code would produce ib = [2,2,3,3,3,3] and new_a = [1.9,1.9,3.2,3.2,3.2,3.2]. Can you tell me by what logic you don't have all the elements of 'a' replaced by their closest elements of 'b'? You may be thinking of an altogether different problem but I don't quite know what that would be unless you are thinking only of values of 'a' that are bracketed on both sides by values in 'b'.<br>
<br>
At the moment I cannot say for sure how this twoyearold code chooses between two equally distant values in 'b'. I would have to study that code carefully. I have reason to believe it selects the first encountered, moving lefttoright, in 'b' among equal candidates, though in choosing between equally distant upper and lower values in 'b' it may give preference to the lower values.<br>
<br>
Roger Stafford

Sun, 01 May 2011 08:58:04 +0000
Re: find nearest,closest value
http://www.mathworks.com/matlabcentral/newsreader/view_thread/243878#833869
Roger Stafford
If I were writing that code today instead of two years ago I would probably prefer the simpler:<br>
<br>
[c,p] = sort(b);<br>
[~,ic] = histc(a,[inf,(c(1:end1)+c(2:end))/2,inf]);<br>
ib = p(ic);<br>
ab = b(ib);<br>
<br>
where 'a' and 'b' are the original row vectors with 'ib' the indices of 'b' elements nearest to the 'a' elements and 'ab' the replacement for 'a' by these nearest 'b' elements.<br>
<br>
Roger Stafford

Sun, 01 May 2011 12:57:04 +0000
Re: find nearest,closest value
http://www.mathworks.com/matlabcentral/newsreader/view_thread/243878#833885
Xiaodong
ImageAnalyst <imageanalyst@mailinator.com> wrote in message <870e82596b6646b9a101b1fdc568f271@j26g2000yqa.googlegroups.com>...<br>
> On Apr 30, 9:51 pm, "Xiaodong " <e20...@gmail.com> wrote:<br>
> > "Bruno Luong" <b.lu...@fogale.findmycountry> wrote in message <i8s483$i4...@fred.mathworks.com>...<br>
> > > 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.<br>
> ><br>
> > > Bruno<br>
> ><br>
> > This is an interesting problem, similar to my present problem:<br>
> > 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.<br>
> ><br>
> > For example,<br>
> > a=[1, 2, 3, 4, 5, 6];<br>
> > b=[2.1, 1.9, 3.2];<br>
> > 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:<br>
> > new_a=[1, 1.9, 3.2, 4, 5, 6];<br>
> > index_replaced_in_a=[2, 2, 3];<br>
> ><br>
> > 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)...<br>
> ><br>
> > Thank you very much!<br>
> ><br>
> > Cheers,<br>
> > Xiaodong<br>
> <br>
> <br>
> Why did the 3 also get replaced? Since the 3 got replaced by 3.2, why<br>
> didn't 4, 5, and 6 also get replaced by 3.2? Why didn't the 1 get<br>
> replaced by 1.9 also? 1.9 was the closest value in b to the 1 in a.<br>
> Is there some greatest difference, where you don't replace if the<br>
> difference is too great?<br>
<br>
My problem may be a little different from the original one: I just want to replace one nearest element in a with one element in b. In a, 4, ,5, 6 are all close to 3.2, but 3 is the nearest element, so I only want to replace 3 with 3.2. This is my logic rule in this problem. In this way, your previous codes above is to be adjusted...<br>
<br>
Thanks for your concern! <br>
Cheers,<br>
Xiaodong

Sun, 01 May 2011 13:21:04 +0000
Re: find nearest,closest value
http://www.mathworks.com/matlabcentral/newsreader/view_thread/243878#833889
Xiaodong
"Roger Stafford" wrote in message <ipiqv9$cja$1@fred.mathworks.com>...<br>
> "Xiaodong" wrote in message <ipiea9$3vr$1@fred.mathworks.com>...<br>
> > This is an interesting problem, similar to my present problem:<br>
> > 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.<br>
> > <br>
> > For example, <br>
> > a=[1, 2, 3, 4, 5, 6];<br>
> > b=[2.1, 1.9, 3.2];<br>
> > 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:<br>
> > new_a=[1, 1.9, 3.2, 4, 5, 6];<br>
> > index_replaced_in_a=[2, 2, 3];<br>
> > <br>
> > 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)...<br>
> > <br>
> > Thank you very much!<br>
> > <br>
> > Cheers,<br>
> > Xiaodong<br>
>         <br>
> To replace elements of vector 'a' by those closest in 'b' in the problem of the original posting (5 Feb 2009) in this thread, just do:<br>
> <br>
> a = b(ib);<br>
> <br>
> using the 'ib' index derived in the code of 16 Feb 2009 (as corrected by Shaun) and I believe the index in 'ib' would be the index vector you speak of.<br>
> <br>
> However, this is not in agreement with your example where the above code would produce ib = [2,2,3,3,3,3] and new_a = [1.9,1.9,3.2,3.2,3.2,3.2]. Can you tell me by what logic you don't have all the elements of 'a' replaced by their closest elements of 'b'? You may be thinking of an altogether different problem but I don't quite know what that would be unless you are thinking only of values of 'a' that are bracketed on both sides by values in 'b'.<br>
> <br>
> At the moment I cannot say for sure how this twoyearold code chooses between two equally distant values in 'b'. I would have to study that code carefully. I have reason to believe it selects the first encountered, moving lefttoright, in 'b' among equal candidates, though in choosing between equally distant upper and lower values in 'b' it may give preference to the lower values.<br>
> <br>
> Roger Stafford<br>
<br>
Sorry for my uncompleted explanation.<br>
<br>
My problem may be similar to a practical issue: taking timedomain sampling for instance, my sampling machine can sample wave magnitude data in a default time series a=[1,2,3,4,5,...] s. But this time series would miss some important peak values and broken lines in the sampled wavelet, which is found locating at b=[1.9, 2,1, 3.2, ...] s. So, I prefer to replace some sampling time series points in 'a' with the peak value time points in 'b', without changing the size of 'a' or repeating any elements in the series. Once I know the indices and values to be changed in 'a', I can update the time series of sampling operations easily. In this way, the sampled wave will have a much more analogical shape to what it should be. <br>
<br>
I think your previous discussion on the original problem will be helpful, except for some small changes...<br>
<br>
Should I start a new thread? <br>
<br>
Xiaodong