pick a random entry from a vector

5 次查看(过去 30 天)
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
entry = vector(randi(length(vector)));

更多回答(1 个)

the cyclist
the cyclist 2015-8-28
If you have the Statistics and Machine Learning Toolbox, you can use the datasample function.

类别

Help CenterFile Exchange 中查找有关 Random Number Generation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by