Unexpected pdist2 behavior?
Info
This question is closed. Reopen it to edit or answer.
Show older comments
According to the documentation, the function
D = pdist2(X,Y,distance)
returns the pairwise distance between rows in X and rows in Y, where the distance, specified with
distance
can be a custom function handle. So for example, I know that all the points in X and Y all lie on the same 3D cylinder, and I want the distance to be the cylindrical geodesic distance, I could set
distance = @cylindricalGeodesic;
However, what I get when using this is not the pair-wise distance between points in X and points in Y:
>> a = [ 1 1 0; -1 1 0];
>> b = [sqrt(2) 0 1;1 1 1];
>> pdist2(a,b,@cylindricalGeodesic)
ans =
1.1107 2.2214
1.1107 2.2214
>> for i = 1:2;for j = 1:2;d(i,j) = cylindricalGeodesic(a(i,:),b(j,:));end;end;d
d =
1.4946 1.0000
3.4790 2.4361
I fully accept this may just be me overlooking something silly, but this behavior seems very unexpected to me: that pdist2 is not equivalent to the pairwise application of the distance function?
Answers (1)
Bruno Luong
on 5 Nov 2018
0 votes
In the DOC of PDIST2 it has been mentioned that the custom distance must able to accept second parameter of (m x 3) as m points in R^3.
I suspect you don't do it and this screws up PDIST2
This question is closed.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!