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!