How do I generate a random number in an interval?

29 次查看(过去 30 天)
Is there a standard function in Matlab that can generate a random rational number in a certain interval?
e.g. ...([1,2]) => 1.35
...([0,4)] => 2.64
...([-3.2, 5.9]) => -3.84

采纳的回答

Sean de Wolski
Sean de Wolski 2013-4-22
See Example 1 in:
  1 个评论
Jeroen
Jeroen 2013-4-22
I eventually used
a+(b-a)*rand(1,1)
to create a random number in the interval [a,b] and unless I've had a lot of luck until now, it works perfectly. This helped me aswell: http://www.mathworks.com/matlabcentral/answers/33121.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by