Permutation function for distance measure

1 visualización (últimos 30 días)
Khairul nur
Khairul nur el 11 de Mzo. de 2021
Respondida: KSSV el 11 de Mzo. de 2021
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

Respuestas (1)

KSSV
KSSV el 11 de Mzo. de 2021
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)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by