4.625

4.6 | 16 ratings Rate this file 102 downloads (last 30 days) File Size: 1.28 KB File ID: #71

distance.m

by R. Bunschoten

 

03 Nov 1999

No BSD License  

A fully vectorized function that computes the Euclidean distance matrix between two sets of vectors.

Download Now | Watch this File

File Information
Description

A fully vectorized function that computes the Euclidean distance matrix between two sets of vectors.

The output is the same as MathWorks' (Neural Network Toolbox) 'dist' funtion (ie, d = dist(A',B), where A is a (DxM) matrix and B a (DxN) matrix, returns the same as my d = distance(A,B) ), but this function executes much faster.

Acknowledgements
This submission has inspired the following:
Efficient K-Nearest Neighbor Search using JIT, IPDM: Inter-Point Distance Matrix
MATLAB release MATLAB 5.2 (R10)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (19)
02 Apr 2002 Jan de Vries

Fantastic!

15 Apr 2003 Peter G

useful...good

21 Oct 2003 ti saigon  
07 Mar 2004 imad ali

need the file

09 Apr 2004 Emily Van Ark

great, fast little function. Exactly what I was looking for!

13 May 2004 uday desai  
20 Nov 2004 Hsuan-Tien Lin

great code

02 Mar 2005 Anton Cervantes  
30 Mar 2005 Babak Taati

good!

15 Apr 2005 Catherine Sweeney-Reed

Great! Thanks!

08 Dec 2006 Enrique Guevara

Is a very fast code. Is faster than any other code for any vectors biger that 8 points.

02 Feb 2007 Markus Buehren

Simple but nice. Performance can still be improved by about 60% by avoiding calls to repmat:

d = abs(aa( ones(size(bb,2),1), :)' + bb( ones(size(aa,2),1), :) - 2*a'*b);

Markus

02 Feb 2007 Markus Buehren

Sorry, I forgot the sqrt:

d = sqrt(abs(aa( ones(size(bb,2),1), :)' + bb( ones(size(aa,2),1), :) - 2*a'*b));

17 May 2007 Xi-Lin Li

very good code

Thanks

09 Oct 2007 A. S.

Very useful, especially Markus' version.

21 Nov 2007 M. Shoaib Sehgal

for vectors it simple to compute using:

distance = norm(A-B)

26 Dec 2007 Panyam Narahari Sastry

Good

19 Feb 2008 Philipp Berens

Quick and clean.

What might be nice: Optional only one argument.

25 Nov 2008 Oliver Woodford

Could be faster still by using bsxfun:
d = sqrt(abs(bsxfun(@plus, aa', bb) - 2*a'*b));

Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
fuzzy logic R. Bunschoten 22 Oct 2008 06:31:31
neural networks R. Bunschoten 22 Oct 2008 06:31:31
euclidean R. Bunschoten 22 Oct 2008 06:31:31
distance R. Bunschoten 22 Oct 2008 06:31:31
dist R. Bunschoten 22 Oct 2008 06:31:31
euclidean Babak Taati 22 Dec 2008 23:07:56
distance Babak Taati 22 Dec 2008 23:07:58
l2 Babak Taati 22 Dec 2008 23:08:01
vectorized Babak Taati 22 Dec 2008 23:08:01
distance Adam Hartshorne 01 Mar 2009 19:48:40
euclidean Clint P. George 16 Apr 2009 09:55:01
 

MATLAB Central Terms of Use

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 Terms prior to use.

Contact us at files@mathworks.com