Clear Filters
Clear Filters

pick a random entry from a vector

5 views (last 30 days)
Lou
Lou on 28 Aug 2015
Answered: the cyclist on 28 Aug 2015
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

Accepted Answer

Walter Roberson
Walter Roberson on 28 Aug 2015
entry = vector(randi(length(vector)));

More Answers (1)

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

Categories

Find more on Random Number Generation in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!