Unexpected pdist2 behavior?
정보
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
이전 댓글 표시
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?
답변 (1개)
Bruno Luong
2018년 11월 5일
0 개 추천
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
댓글 수: 0
이 질문은 마감되었습니다.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!