Creating a function that does the same as myrandperm(n,k)
조회 수: 4 (최근 30일)
이전 댓글 표시
I have to create a function,which does the same as myrandperm(n,k). I thought of creating a for loop which goes from 1 to k in which an array p(i) gets initialised by a random integer of an array n. And then p(i) gets deleted from from the array n.
But I didnt found a function that gives me a random integer from an array.
Do you guys have any ideas?
댓글 수: 0
채택된 답변
Walter Roberson
2020년 11월 12일
randi(length(n))
댓글 수: 4
Walter Roberson
2020년 11월 19일
random index = randi(length(d))
random value = d(random index)
delete entry "random index" from d
lathe, rinse, repeat
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!