How can I sort a vector in a random manner in MATLAB?
77 次查看(过去 30 天)
显示 更早的评论
I have a 1-dimensional array and would like to sort the elements of this vector randomly.
采纳的回答
MathWorks Support Team
2011-6-29
To sort the elements of a vector randomly you can use the RANDPERM() function.
RANDPERM(n) returns a random permutation of the integers 1:n.
a = [1 2 3 4 5];
a_rand = a(randperm(length(a)));
2 个评论
Dyuman Joshi
2020-11-25
编辑:Dyuman Joshi
2020-11-25
How to obtain all possible random permutations of an given array?
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Shifting and Sorting Matrices 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!