How do you use randperm on a vector?
22 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have a vector
A = repmat(1:6, [1 4])
and I need to use randperm to randomize it. How would I do that?
0 commentaires
Réponse acceptée
Kristi
le 14 Fév 2016
A = repmat(1:6, [1 4])
B = A(randperm(24))
1 commentaire
Guillaume
le 14 Fév 2016
B = A(randperm(numel(A))
would be a lot better since it will work regardless of the size of A. As a rule avoid hardcoded constants, particularly as it's trivial to obtain the number of elements in A.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!