Azzera filtri
Azzera filtri

pick a random entry from a vector

5 visualizzazioni (ultimi 30 giorni)
Lou
Lou il 28 Ago 2015
Risposto: the cyclist il 28 Ago 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

Risposta accettata

Walter Roberson
Walter Roberson il 28 Ago 2015
entry = vector(randi(length(vector)));

Più risposte (1)

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

Categorie

Scopri di più su Random Number Generation in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by