# 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?

56 visualizzazioni (ultimi 30 giorni)
yuxiao qi il 29 Mag 2024 alle 17:25
Modificato: John D'Errico il 3 Giu 2024 alle 13:24

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 CommentoMostra -1 commenti meno recentiNascondi -1 commenti meno recenti
John D'Errico il 3 Giu 2024 alle 13:22
Modificato: John D'Errico il 3 Giu 2024 alle 13:24
@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?

Accedi per commentare.

### Risposta accettata

Star Strider il 29 Mag 2024 alle 17:31
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 CommentiMostra 5 commenti meno recentiNascondi 5 commenti meno recenti
yuxiao qi il 29 Mag 2024 alle 19:50
Thank you for your answer. It starts from 0 and the part in the title has been modified.
Star Strider il 29 Mag 2024 alle 20:25
My pleasure!
Thank you for clarifying this.

Accedi per commentare.

### Più risposte (1)

Torsten il 29 Mag 2024 alle 17:28
Spostato: Torsten il 29 Mag 2024 alle 17: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>
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Categorie

Scopri di più su Uniform Distribution (Continuous) in Help Center e File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by