Floating numbers generation in a range
Afficher commentaires plus anciens
I Want to generate an array of 100 Different random floating numbers in the range 2.2 to 22. Please help me with this.
Réponses (2)
Roger Stafford
le 21 Sep 2013
0 votes
What kind of probability distribution do you wish these numbers to have over this interval? If it is to be uniform use 'rand' with appropriate scaling and offset.
4 commentaires
BISWA
le 21 Sep 2013
Roger Stafford
le 21 Sep 2013
I think you were using 'randi', not 'rand'. The 'randi' function returns only integers, whereas 'rand' returns fractional values. The probability of getting an integer output from 'rand' is exceedingly small. I have personally never seen one.
BISWA
le 21 Sep 2013
Image Analyst
le 21 Sep 2013
You never looked up rand() in the help did you? Otherwise you would have noticed Example 1 which solves your problem
Example 1
Generate values from the uniform distribution on the interval [a,b]:
r = a + (b-a).*rand(100,1);
and I'm pretty sure you would have figured out a is 2.2 and b is 22 and you wouldn't have needed to wait for Simon to do it for you. Please mark the answer as Accepted.
Catégories
En savoir plus sur Creating and Concatenating Matrices 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!