Prevent repeating number in a vector

조회 수: 15 (최근 30일)
hany salem
hany salem 2017년 7월 10일
댓글: Star Strider 2017년 7월 12일
Hi all, If I have any random matrix: [2 4 5 6 4] The number 4 is repeated here. I would like some help in being able to prevent this repeating. your help is appreciated. Hany

채택된 답변

Star Strider
Star Strider 2017년 7월 10일
I am not certain what you want.
If you want a random matrix that prevents repeats, this works:
M = perms(unique([2 4 5 6 4]));
The randperm function is another option if you have a vector of non-duplicating numbers and you want the perumtations of it.
  댓글 수: 5
hany salem
hany salem 2017년 7월 12일
If I have any random matrix: [2 4 5 6 4; 3 5 3 2 6] The numbers 4 and 3 are repeated in rows one and two, respectively. I would like some help in being able to prevent this repeating. The randperm function is okay for doing the requirement in vectors. Is it okay here in a matrix?
Star Strider
Star Strider 2017년 7월 12일
The randperm function only outputs vectors, so to create a matrix, you will have to use it in a loop. An alternative is the perms function.
You may have to explore the documentation (follow the links at the end of the randperm documentation page) to find the function that most closely approximates what you want to do.

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

추가 답변 (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