How can I sort a vector in a random manner in MATLAB?
53 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
MathWorks Support Team
le 29 Juin 2011
Modifié(e) : Dyuman Joshi
le 25 Nov 2020
I have a 1-dimensional array and would like to sort the elements of this vector randomly.
Réponse acceptée
MathWorks Support Team
le 29 Juin 2011
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 commentaires
Dyuman Joshi
le 25 Nov 2020
Modifié(e) : Dyuman Joshi
le 25 Nov 2020
How to obtain all possible random permutations of an given array?
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Shifting and Sorting Matrices dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!