How can I select random element from one of the array in structure?

I have a structure named peer which has 2 arrays value[] and age[]. I want to select random element from value[]and assign it to variable p. Could you please guide me about it? Thanks

Respuestas (1)

p = peer.value(randi(numel(peer.value)))
If you have the statistics toolbox then you can use randsample I think the routine name is

Categorías

Más información sobre Random Number Generation en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 8 de Sept. de 2015

Respondida:

el 8 de Sept. de 2015

Community Treasure Hunt

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

Start Hunting!

Translated by