rand integer values from an array
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have an array that contains some integer.
i.e
A=[1 5 7 9]
I would choose a rand value from this vector. Which could be the best way?
0 commentaires
Réponse acceptée
Wayne King
le 20 Sep 2012
Modifié(e) : Wayne King
le 20 Sep 2012
You can use randi
index = randi(length(A(:)),1,1);
A(index)
for a 1-D vector, you can just do length(A), but length(A(:)) will work with a matrix as well.
0 commentaires
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!