How to use Matlab to generate a discrete uniformly distributed decimal with a value range of {0, 0.05} and a step size of 0.01?

조회 수: 3 (최근 30일)

The randi function in matlab generates uniformly distributed pseudo-random integers. If I want to generate discrete uniformly distributed random values ​​(decimals) in the range of {0,0.05} and a step size of 0.01, how can I do it?

  댓글 수: 1
John D'Errico
John D'Errico 2024년 6월 3일
편집: John D'Errico 2024년 6월 3일
@yuxiao qi Why did you need to post this exact question again 5 days later, (now closed as a duplicate), when you already accepted an enswer to this question? Are you testing us to see if we remember it was you?

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

채택된 답변

Star Strider
Star Strider 2024년 5월 29일
Perhaps something like this —
rv = randi([0 5], 1, 100)/100
rv = 1x100
0 0.0100 0.0200 0 0.0200 0 0.0400 0.0200 0.0400 0.0400 0 0 0.0300 0.0100 0.0300 0 0.0100 0.0300 0 0.0400 0.0200 0.0100 0.0200 0.0500 0.0300 0.0500 0.0400 0.0200 0.0300 0.0400
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
figure
histogram(rv, 5)
grid
.
  댓글 수: 7
yuxiao qi
yuxiao qi 2024년 5월 29일
Thank you for your answer. It starts from 0 and the part in the title has been modified.

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

추가 답변 (1개)

Torsten
Torsten 2024년 5월 29일
이동: Torsten 2024년 5월 29일
n = 10;
x = randi(6,n,1);
x = (x-1)*0.01
x = 10x1
0.0500 0.0300 0 0 0 0.0500 0.0500 0.0100 0.0200 0.0100
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>

Community Treasure Hunt

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

Start Hunting!

Translated by