Random number generator help

2 vues (au cours des 30 derniers jours)
Kashish Pilyal
Kashish Pilyal le 31 Mai 2022
Réponse apportée : Voss le 31 Mai 2022
I am looking to generate random numbers between a certain set of decimal numbers (for eg: 0.3 to 0.4). I tried using rand command but if anyone has a workaround?

Réponse acceptée

Voss
Voss le 31 Mai 2022
rand gives you number(s) between 0 and 1, so with appropriate scaling and offsetting, you can use it to get number(s) from any given range:
data = 0.3 + 0.1*rand(1,100) % 100 numbers between 0.3 and 0.4
data = 1×100
0.3596 0.3187 0.3503 0.3990 0.3179 0.3482 0.3384 0.3025 0.3906 0.3738 0.3543 0.3069 0.3705 0.3117 0.3616 0.3272 0.3565 0.3828 0.3806 0.3173 0.3632 0.3188 0.3767 0.3447 0.3255 0.3521 0.3875 0.3934 0.3428 0.3297
plot(data)

Plus de réponses (0)

Catégories

En savoir plus sur Random Number Generation dans Help Center et File Exchange

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by