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

回答(1 个)

KSSV
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)

类别

Help CenterFile 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!

Translated by