pick a random entry from a vector

Hello, is there a matlab function that picks a random entry from a vector? I solved the problem with
i=randperm(length(vector),1),
entry=vector(i).
But i wondered if there is a more elegant solution. Thank you

 採用された回答

Walter Roberson
Walter Roberson 2015 年 8 月 28 日

4 投票

entry = vector(randi(length(vector)));

その他の回答 (1 件)

the cyclist
the cyclist 2015 年 8 月 28 日

1 投票

If you have the Statistics and Machine Learning Toolbox, you can use the datasample function.

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

質問済み:

Lou
2015 年 8 月 28 日

回答済み:

2015 年 8 月 28 日

Community Treasure Hunt

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

Start Hunting!

Translated by