Floating numbers generation in a range

21 次查看(过去 30 天)
BISWA
BISWA 2013-9-21
I Want to generate an array of 100 Different random floating numbers in the range 2.2 to 22. Please help me with this.

回答(2 个)

Roger Stafford
Roger Stafford 2013-9-21
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 个评论
BISWA
BISWA 2013-9-21
Please post the code here which will generate an array of 50 floating numbers between 2.2 to 22.
Image Analyst
Image Analyst 2013-9-21
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.

请先登录,再进行评论。


Simon
Simon 2013-9-21
19.8*rand(50, 1) +2 .2

类别

Help CenterFile Exchange 中查找有关 Random Number Generation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by