How do I generate a random number in an interval?

24 ビュー (過去 30 日間)
Jeroen
Jeroen 2013 年 4 月 22 日
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 Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by