All possible permutation of a given vector.
Mostrar comentarios más antiguos
Given a vector, e.g [1 2 3 4 1], I would like to obtain all the possible permutations with NO REPETITION and NO ROTATION.
With
v = [1 2 3 4 1];
P = unique(perms(v),'rows');
I can avoid repetition but no rotation.
With rotation I mean that [1 2 1 4 3] and [2 1 4 3 1] are the same vector because the sequence is the same, just view from a different initial position.
I would like to be able to obtain all the possible combinations that avoid also this fact (rotation).
Thanks
1 comentario
Rik
el 23 de Jul. de 2019
I suspect there are two options:
- looping through your array (from end to beginning) and remove all rotations (use circshift)
- design your own implementation of perms that avoids rotations
Neither is likely to be fast, and the first will also require the generation of a very large array for slightly larger vectors.
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Ordinary Differential Equations en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!