Path: news.mathworks.com!not-for-mail
From: "Arvind Iyer" <aiyer@ict.usc.edu>
Newsgroups: comp.soft-sys.matlab
Subject: Vectorization of Euclidean distance calculation
Date: Sat, 8 Nov 2008 23:10:04 +0000 (UTC)
Organization: Institute of Creative Technologies
Lines: 14
Message-ID: <gf568c$ft5$1@fred.mathworks.com>
Reply-To: "Arvind Iyer" <aiyer@ict.usc.edu>
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 1226185804 16293 172.30.248.38 (8 Nov 2008 23:10:04 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sat, 8 Nov 2008 23:10:04 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1412562
Xref: news.mathworks.com comp.soft-sys.matlab:499689


The norm command provides a quick way of calculating Euclidean distance in an N-dimensional space.
e.g,
N = 50;
x1 = randn(1,N);
x2 = randn(1,N);
euclid_dist = norm(x1-x2);

Consider I have a M points x1, x2.....xM stored in an MxN matrix
[x1;x2.....;xM]
I now want to find the Euclidean distance of each of these point from a test point xT.

How can this be done in a vectorized way without loops?
I am interested in speeding this up because M is really large in my problem.