Question

I have a point-cloud, for which i want to calculate the distance between all individual points in Matlab (preferably without duplicates).

The matrix with the coordinates is formatted as: points [ p x n x d ]. Where p = 1 (for now), n is as large as the number of points and d as large as the number of dimensions (3 in this case).

This is the data i have:

  • points(:,:,1) = 1 2 3
  • points(:,:,2) = 4 5 6
  • points(:,:,3) = 7 8 9

So i have three points in three dimensions. Now using pdist, i have tried to calculate the euclidian distance between each point using distances = pdist(points(:,1:3)); and distances = pdist(X(:,:,1:3)); But both just return an empty matrix.

Does anyone know how to use pdist to calculate these distances? It should return 3 distances, instead of 0, but i must be doing something wrong.


Btw. this question is a follow up to this one. I asked it in the comments at first, but thought it deserved a new question because it is a considerable expansion of the original question.

Was it helpful?

Solution

Try

distances = pdist(squeeze(X(:,:,1:3)));

or the transpose of squeeze(...) if that isn't correct.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top