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

 Akzeptierte Antwort

Walter Roberson
Walter Roberson am 28 Aug. 2015

4 Stimmen

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

Weitere Antworten (1)

the cyclist
the cyclist am 28 Aug. 2015

1 Stimme

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

Kategorien

Community Treasure Hunt

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

Start Hunting!

Translated by