random entry selection from a matrix

18 vues (au cours des 30 derniers jours)
Peter D
Peter D le 23 Juil 2012
how can I select any element randomly from a 1 x n matrix?

Réponses (1)

Doug Hull
Doug Hull le 23 Juil 2012
v = [1:10]
vi = randi(numel(v));
choice = v(vi)
  1 commentaire
Walter Roberson
Walter Roberson le 23 Juil 2012
Doug, you missed your chance to say
choice = v(randperm(numel(v),1));

Connectez-vous pour commenter.

Catégories

En savoir plus sur Logical 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!

Translated by