Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: euclidean distance
Date: Thu, 2 Jul 2009 03:24:01 +0000 (UTC)
Organization: Indian Institute of Technology
Lines: 17
Message-ID: <h2h98h$ll2$1@fred.mathworks.com>
References: <h2dp5l$p98$1@fred.mathworks.com> <h2frkm$kb6$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1246505041 22178 172.30.248.38 (2 Jul 2009 03:24:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 2 Jul 2009 03:24:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 223861
Xref: news.mathworks.com comp.soft-sys.matlab:552261


Hi peter,
Thank you very much.
Your solution was very helpful to me in my situation (except that I have 150 dimensions instead of 3 !). 
In my situation, I just need the index (of point) of B which is nearest to each point in B. Instead of finding the pairwise distance and using min command, can I bypass this laborious calculation of calculating Euclidean distance to directly arrive at the indices.


regards,
ramana
 
> But most likely, you want to loop over 1:3 within 1:2000, and sum the squared diffs for each dimension of each point in B to all points in A, vectorized.  This is essentially what John suggested with BSXFUN (though I think those ought to be @minus's, wrapped in .^2's).  Here's an "unrolled loop" version.
> 
> Eucl_Ideal = zeros(size(A,1),size(B,1));
> for i = 1:size(B,1);
>     Eucl_Ideal(:,i) = sqrt((A(:,1)-B(i,1)).^2 + (A(:,2)-B(i,2)).^2 + (A(:,3)-B(i,3)).^2);
> end
> 
> There's a good deal that can be learned about memory access and vectorization from this example.  Hope this helps.