필터 지우기
필터 지우기

Creating a function that does the same as myrandperm(n,k)

조회 수: 4 (최근 30일)
Furkan Karaman
Furkan Karaman 2020년 11월 12일
댓글: Furkan Karaman 2020년 11월 19일
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?

채택된 답변

Walter Roberson
Walter Roberson 2020년 11월 12일
randi(length(n))
  댓글 수: 4
Walter Roberson
Walter Roberson 2020년 11월 19일
random index = randi(length(d))
random value = d(random index)
delete entry "random index" from d
lathe, rinse, repeat
Furkan Karaman
Furkan Karaman 2020년 11월 19일
@Rik ,because our professor does not want it, as a challenge for us.
@Walter thank you

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by