Create a matrix using rand function with a value range

Hi all, how can I create a 50x50 matrix using Random (rand) function while the condition is all the values of the matrix will be in between 0 to 0.004?

 채택된 답변

Stephen23
Stephen23 2021년 10월 28일
0.004*rand(50,50)

댓글 수: 2

Ashfaq Ahmed
Ashfaq Ahmed 2021년 10월 28일
편집: Ashfaq Ahmed 2021년 10월 28일
I am right now using this line: a = 0.004 + (0.004-0.000).*rand(50,50);
That's almost correct. That's the syntax suggested in the "Random Numbers Within Specified Interval" example on the documentation page for the rand function but you're using a and b inconsistently.
You want to generate numbers with the lower limit a being 0 and the upper limit b being 0.004.
a = 0;
b = 0.004;
N = 10;
r = a + (b-a).*rand(N,1)
r = 10×1
0.0018 0.0005 0.0015 0.0001 0.0028 0.0025 0.0028 0.0026 0.0019 0.0024
checkInterval = all((a < r) & (r < b))
checkInterval = logical
1

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

질문:

2021년 10월 28일

댓글:

2021년 10월 28일

Community Treasure Hunt

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

Start Hunting!

Translated by