selecting a random value within a specific interval

조회 수: 28 (최근 30일)
Rengin
Rengin 2015년 2월 10일
댓글: Image Analyst 2015년 2월 10일
Hello,
vmin=0.90;
vmax=1.15;
How can I select a random value between 0.90 and 1.15?
Thx!

채택된 답변

Image Analyst
Image Analyst 2015년 2월 10일
Did you look up rand() in the help? It's one of the examples:
Random Numbers Within Specified Interval
Generate a 10-by-1 column vector of uniformly distributed numbers in the interval [-5,5].
r = -5 + (5+5)*rand(10,1)
r =
3.1472
4.0579
-3.7301
4.1338
1.3236
-4.0246
-2.2150
0.4688
4.5751
4.6489
In general, you can generate N random numbers in the interval [a,b] with the formula r = a + (b-a).*rand(N,1);.
  댓글 수: 3
Guillaume
Guillaume 2015년 2월 10일
Yes, but the OP never mentioned normal, so the assumption is they want a uniform distribution.
Image Analyst
Image Analyst 2015년 2월 10일
If a normal distribution is wanted, use randn(). Other related functions are also found at the bottom of the help in the "See Also" section.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

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