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

Réponses (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

Catégories

En savoir plus sur Random Number Generation dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by