random entry selection from a matrix

2 ビュー (過去 30 日間)
Peter D
Peter D 2012 年 7 月 23 日
how can I select any element randomly from a 1 x n matrix?

回答 (1 件)

Doug Hull
Doug Hull 2012 年 7 月 23 日
v = [1:10]
vi = randi(numel(v));
choice = v(vi)
  1 件のコメント
Walter Roberson
Walter Roberson 2012 年 7 月 23 日
Doug, you missed your chance to say
choice = v(randperm(numel(v),1));

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by