Prevent repeating number in a vector
2 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
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 个评论
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 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!