Problem 43007. Euclidean interpoint distance matrix
The Euclidean distance between two points in a pdimensional space is a really common thing to compute in the field of computational geometry. In fact, it is pretty easy to do. norm(uv) would seem to do the trick, for vectors u and v.
But what if you have a large number of points between which you want to compute ALL of those distances between every pair of points? In this problem, given an n by p array A, where each row of the matrix will be viewed as containing the coordinates of one pdimensional point, you need to compute the n by n interpoint distance matrix.
Thus, D(i,J) will be the Euclidean distance between the i'th and j'th rows of A. Of course, D will be a symmetric matrix, with zeros on the diagonal.
So you can test your code, here is an example:
A = [1 1 5 2 2 2 4 5]
format short g D = interDist(A) D = 0 4.1231 1.4142 5 4.1231 0 3 3.1623 1.4142 3 0 3.6056 5 3.1623 3.6056 0
Thus, thinking of the points [1 1] and [5 2] as the coordinates of two points in the (x,y) plane, the Euclidean distance between them in that plane is 4.1231...
As you can see, the matrix is symmetric, with zeros on the main diagonal. That must always happen, since the distance between any point and itself must be zero.
Solution Stats
Problem Comments
Solution Comments
Show commentsProblem Recent Solvers27
Suggested Problems

Sum the entries of each column of a matrix which satisfy a logical condition.
160 Solvers

508 Solvers

Find out missing number from a vector of 9 elements
294 Solvers

174 Solvers

359 Solvers
More from this Author4
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!