random selection of number among 2 numbers
12 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
How do I randomly choose among 0 and 2 in matlab ? I have display the choosen number also.
Note: The choosen number should be either 0 or 2 not something in between.
0 commentaires
Réponses (1)
the cyclist
le 9 Juin 2021
Modifié(e) : the cyclist
le 9 Juin 2021
Here are a couple ways:
2*randi([0 1])
2*round(rand())
2 commentaires
Steven Lord
le 9 Juin 2021
A generalized version of Jan's answer:
Pool = (0:5).^2;
desiredSize = [1 7];
x = Pool(randi(numel(Pool), desiredSize))
Voir également
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!