Thread Subject: Vectorization of Euclidean distance calculation

Subject: Vectorization of Euclidean distance calculation

From: Arvind Iyer

Date: 8 Nov, 2008 23:10:04

Message: 1 of 2

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.

Subject: Vectorization of Euclidean distance calculation

From: John D'Errico

Date: 8 Nov, 2008 23:58:02

Message: 2 of 2

"Arvind Iyer" <aiyer@ict.usc.edu> wrote in message <gf568c$ft5$1@fred.mathworks.com>...
> 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.


http://www.mathworks.com/matlabcentral/fileexchange/18937

John

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
vectorization Arvind Iyer 8 Nov, 2008 18:15:04
norm Arvind Iyer 8 Nov, 2008 18:15:04
euclidean distance Arvind Iyer 8 Nov, 2008 18:15:04
rssFeed for this Thread

Public Submission Policy

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.

Contact us at files@mathworks.com