Effacer les filtres
Effacer les filtres

How can I generate a random real numbers from a specific range?

2 vues (au cours des 30 derniers jours)
Hi all,
I want to pick real numbers randomly from a specific range (0 , 0.2304). Can any one help me to do that?
Thank you
  1 commentaire
Image Analyst
Image Analyst le 13 Sep 2014
Did you look up rand in the help? It's the very first example.

Connectez-vous pour commenter.

Réponse acceptée

Azzi Abdelmalek
Azzi Abdelmalek le 13 Sep 2014
Modifié(e) : Azzi Abdelmalek le 13 Sep 2014
rand*0.2304
For a general case (a,b)
a=0.12
b=0.45
out=a+(b-a)*rand;
  2 commentaires
Abdulatif Alabdulatif
Abdulatif Alabdulatif le 14 Sep 2014
Thanks for the answer. However, is there a way to reduce the generated number to 4 float point numbers?
for example:
0.187712337344988 --> 0.1877
Thanks again!
Image Analyst
Image Analyst le 14 Sep 2014
Modifié(e) : Image Analyst le 14 Sep 2014
out4decimalPlaces = round(out * 10000)/10000
Please mark Azzi's answer as Accepted now.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Logical 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!

Translated by