Generate multiple random numbers in MatLab?
13 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
How do I generate multiple exponential random variables in matlab?
I know the code:
exprnd(mu)
but lets say I want 1000 random variables, how can I do this so I don't have to keep typing out "exprnd(mu)" 1000 times?
EDIT: Is it simple a matrix (like maybe 10 x 100 or something) and then there obviously would be a 1000 numbers in this matrix?
0 comentarios
Respuesta aceptada
Wayne King
el 3 de Oct. de 2012
Editada: Wayne King
el 3 de Oct. de 2012
mu = 1;
x = exprnd(mu,1000,1);
hist(x)
MATLAB random number generators all work like this; this is documented in the command line help and the documentation. Have you read that?
0 comentarios
Más respuestas (1)
Daniel Shub
el 3 de Oct. de 2012
Not to be rude, but have you read the help?
EXPRND Random arrays from exponential distribution.
R = EXPRND(MU) returns an array of random numbers chosen from the
exponential distribution with mean parameter MU. The size of R is
the size of MU.
R = EXPRND(MU,M,N,...) or R = EXPRND(MU,[M,N,...]) returns an
M-by-N-by-... array.
It seems to me to be pretty clear. The first method says you can do
R = exprnd(mu*ones(1000, 1));
while the second method says you can also do
R = exprnd(mu, 1000, 1);
0 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!