How can I generate random numbers in a range with decimal steps?

36 次查看(过去 30 天)
Hi
How can I generate a random decimal number inbetween a range of 0 and 0.5 (i.e. 0, 0.1, 0.2, 0.3, 0.4, 0.5)?
  1 个评论
Image Analyst
Image Analyst 2017-6-25
I'm not sure what you're asking. Do you want one random number in a range 0-0.5 like you'd get from
r=0.5*rand()
or do you want to pick a number at random from that list of 6 predefined numbers you listed? Or something other than those two options?

请先登录,再进行评论。

采纳的回答

Stephen23
Stephen23 2017-6-25
编辑:Stephen23 2017-6-25
>> V = 0:0.1:0.5; % define the numbers
>> V(randi([1,numel(V)]))
ans =
0.4
>> V(randi([1,numel(V)]))
ans =
0.2
>> V(randi([1,numel(V)]))
ans =
0.5
>> V(randi([1,numel(V)]))

更多回答(1 个)

Jan
Jan 2017-6-25
randi([0, 5]) / 10

类别

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