How can I set the values of matrix in interval <a, b>?

조회 수: 4 (최근 30일)
Ihor
Ihor 2022년 12월 4일
댓글: DGM 2022년 12월 4일
Generate a matrix Ru of pseudo-random floating point values from a uniform distribution, a matrix Ri of pseudo- random integer
values from a uniform distribution and a matrix Rn of pseudo-random values from a normal distribution. Let the size of all
matrices be M x N. Let the expected value of Rn be m = 8 and variance v = 3. Let the values of Ru an Ri be from the interval < a,
b > = < 4, 9 >.
Rn = rand( M, N ) ;
Ru = randn( M, N) ;
Ri = randi( [a, b], M, N ) ; % here I know how to set the interval <a, b>
  댓글 수: 2
Stephen23
Stephen23 2022년 12월 4일
편집: Stephen23 2022년 12월 4일
Original question by Ihor retrieved from Google cache:
How can I set the values of matrix in interval <a, b>?
Generate a matrix Ru of pseudo-random floating point values from a uniform distribution, a matrix Ri of pseudo- random integer
values from a uniform distribution and a matrix Rn of pseudo-random values from a normal distribution. Let the size of all
matrices be M x N. Let the expected value of Rn be m = 8 and variance v = 3. Let the values of Ru an Ri be from the interval < a,b > = < 4, 9 >.
Rn = rand( M, N ) ;
Ru = randn( M, N) ;
Ri = randi( [a, b], M, N ) ; % here I know how to set the interval <a, b>
Rik
Rik 2022년 12월 4일
I recovered the removed content from the Google cache (something which anyone can do). Editing away your question is very rude. Someone spent time reading your question, understanding your issue, figuring out the solution, and writing an answer. Now you repay that kindness by ensuring that the next person with a similar question can't benefit from this answer.

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

채택된 답변

DGM
DGM 2022년 12월 4일
편집: DGM 2022년 12월 4일
Start with:
m = 500;
n = 500;
rrange = [4 9];
mn = 8;
vr = 3;
% uniform distribution with a specified range
Ru = rrange(1) + range(rrange)*rand(m,n);
[min(Ru(:)) max(Ru(:))]
ans = 1×2
4.0000 9.0000
% normal distribution with specified mean, variance
Rn = mn + sqrt(vr)*randn(m,n);
[mean(Rn(:)) var(Rn(:))]
ans = 1×2
7.9939 3.0058
% discrete uniform random integers
Ri = randi(rrange,m,n);
[min(Ri(:)) max(Ri(:))]
ans = 1×2
4 9
  댓글 수: 3
Ihor
Ihor 2022년 12월 4일
Is there tha way in which I can change the range() function because of it in other ToolBox?
DGM
DGM 2022년 12월 4일
oof. I forgot that was in stats toolbox.
Ru = rrange(1) + (rrange(2)-rrange(1))*rand(m,n);

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

추가 답변 (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