random entry selection from a matrix

18 visualizaciones (últimos 30 días)
Peter D
Peter D el 23 de Jul. de 2012
how can I select any element randomly from a 1 x n matrix?

Respuestas (1)

Doug Hull
Doug Hull el 23 de Jul. de 2012
v = [1:10]
vi = randi(numel(v));
choice = v(vi)
  1 comentario
Walter Roberson
Walter Roberson el 23 de Jul. de 2012
Doug, you missed your chance to say
choice = v(randperm(numel(v),1));

Iniciar sesión para comentar.

Categorías

Más información sobre Logical en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by