Info
La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.
Random vector non repeated otherwise create new vector
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Hello,
I have number list from 1 to 5. We know there are 120 different permutation for these. I want to write a rule that for my algorithm, I want to create a permutation that does not creaated before. For example,
1 2 3 4 5 first
2 3 4 5 1 second
...
2 3 4 5 1 nth it shouldn't be created. It is already in the second iteration.
So, by this manner creations should end at most 120th trial.
Can you help me solve this? I'm using randperm
Thank you.
2 comentarios
Guillaume
el 12 de Jul. de 2019
randperm doesn't keep track of previously generated permutations, so it's never going to be useful for this.
Why can't you just generate at once the 120 permutations (with perm) and shuffle them if needed?
Respuestas (2)
Brendan Hamm
el 12 de Jul. de 2019
p = perms(1:5);
idx = randi([1,size(p,1)]);
selection = p(idx,:)
0 comentarios
La pregunta está cerrada.
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!