help random numbers generator

15 visualizzazioni (ultimi 30 giorni)
Daniele1
Daniele1 il 23 Mag 2020
Risposto: Jeff Miller il 25 Mag 2020
Hi everyone, I'd like to know how to generate a set of random numbers with normal distribution (randn) belonging to a range defined by me.
To make it easier:
I want to generate 10 random numbers between [-0.5 0.5] using randn.
Thanks for your attention

Risposta accettata

Jeff Miller
Jeff Miller il 25 Mag 2020
Good. Here it is as an 'official' answer:
pd = makedist('Normal');
t = truncate(pd,-0.5,0.5);
r = random(t,10,1);

Più risposte (1)

KSSV
KSSV il 23 Mag 2020
a = -0.5 ;
b = 0.5 ;
N = 10 ;
r = (b-a).*randn(N,1) + a;
  7 Commenti
Jeff Miller
Jeff Miller il 25 Mag 2020
If that would work, then I guess this is what you are after:
pd = makedist('Normal');
t = truncate(pd,-0.5,0.5);
r = random(t,10,1);
Daniele1
Daniele1 il 25 Mag 2020
it works perfectly! thanks

Accedi per commentare.

Categorie

Scopri di più su Random Number Generation 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