Filter löschen
Filter löschen

random entry selection from a matrix

1 Ansicht (letzte 30 Tage)
Peter D
Peter D am 23 Jul. 2012
how can I select any element randomly from a 1 x n matrix?

Antworten (1)

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

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by