Permutation function for distance measure
1 次查看(过去 30 天)
显示 更早的评论
Hi, i want to get the possible number of distance between k number of coordinate. Assume that we have 2 coordinate (k=2), then the possible distance are (1,2),(2,1). Thus the number of distance for k=2 is 2.
Another example is if k=3, the possible coordinate are (1,2),(1,3),(2,3),(2,1),(3,1),(3,2).
However, i also need to assume that distance between (1,2) and (2,1) is same. Thus if k=2, the possible coordinate is 1 and if k=3, possible coordinate is 3.
I had tried the permutation function in matlab, but it do not suitable , especially when k=3 as below.
Hope the explainantion is clear. Please help to suggest other suitable function or possible code. TQIA
v = [1 2 3];
P = perms(v)
the output:
P =
3 2 1
3 1 2
2 3 1
2 1 3
1 3 2
1 2 3
0 个评论
回答(1 个)
KSSV
2021-3-11
You can get the distances between each pair using pdist. From this you can make decision.
v = [1 2 3];
P = perms(v)
d = pdist(P)
Z = squareform(d)
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Statistics and Machine Learning Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!