[Solved] distance points 3D [duplicate]


If you don’t have the statistics toolbox, it is not the correct function to use. If you do – then it is one of many functions you could use. You can also do something like:

sz = size(A);
A1 = reshape(A, [1 sz]);
A2 = permute(A1, [2 1 3]);
D = sqrt(sum(bsxfun(@minus, A1, A2).^2,3));

This calculates the distance between any two points explicitly (thus, does twice as much work, and takes over twice as much space: 6400 instead of 3180 elements). However, it’s easier to look up the distance between any two points.

You can then compare the result of this calculation with the one you get from pdist, and convince yourself whether it’s the same. Be careful – pdist returns a vector by default, so you need to look at the documentation to make sure you understand how to interpret it. The function squareform can help you:

difference = sum(abs(squareform(D)) - pdist(A, 'euclidean'));

It depends on what you want… and what your definition of “the right function” is…

2

solved distance points 3D [duplicate]