Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Random vector non repeated otherwise create new vector

조회 수: 1 (최근 30일)
Yigitalp Ozmen
Yigitalp Ozmen 2019년 7월 12일
마감: MATLAB Answer Bot 2021년 8월 20일
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
Guillaume
Guillaume 2019년 7월 12일
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?
Stephen23
Stephen23 2019년 7월 12일
Create all permutations, then pick randomly.

답변 (2개)

Brendan Hamm
Brendan Hamm 2019년 7월 12일
p = perms(1:5);
idx = randi([1,size(p,1)]);
selection = p(idx,:)

Yigitalp Ozmen
Yigitalp Ozmen 2019년 7월 12일
Thank you for your answers. What about for bigger numbers such as 10. Matlab cant generate 10!. But maybe it can generate permutations different from previous ones. Is it achivable?

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by