How to generate a random decimal number between -1 and 1?
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I'm trying to use rand below but it is giving me [ ].
rand([-1 1]);
1 commentaire
Ameer Hamza
le 29 Oct 2020
Modifié(e) : Ameer Hamza
le 29 Oct 2020
The answer here: https://www.mathworks.com/matlabcentral/answers/630328-how-to-generate-a-random-decimal-number-between-1-0-and-1-52 will also work for this question. Just use
range = [-1 1]
Réponse acceptée
Plus de réponses (1)
Walter Roberson
le 29 Oct 2020
rand*2-1
Note this will not generate exactly -1 or exactly 1
0 commentaires
Voir également
Catégories
En savoir plus sur Random Number Generation 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!