Pair-wise Euclidean Distance Matrix

Version (2.62 KB) by Quan Wang
Computing the distance matrix without loops


Updated 20 May 2014

View License

This is a very simple function to compute pair-wise Euclidean distances within a vector set, from between two vector sets. Although simple, it is very useful. Using loops will be too slow.
D=distanceMatrix(X), where X is N*d data, and D is N*N distance matrix.

or D=distanceMatrix2(X,Y).

Cite As

Quan Wang (2023). Pair-wise Euclidean Distance Matrix (, MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2013b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Find more on Statistics and Machine Learning Toolbox in Help Center and MATLAB Answers

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes

Changed the description.

Added distance matrix from X to Y.