Permutation function for distance measure

조회 수: 1 (최근 30일)
Khairul nur
Khairul nur 2021년 3월 11일
답변: KSSV 2021년 3월 11일
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에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by