create Non-uniform distribution
11 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
nirit
el 26 de Dic. de 2015
Respondida: Roger Stafford
el 27 de Dic. de 2015
Hello!
I want to create non -uniform distribution using rand. for example, let X be random integer number with :
X=
0 w.p 1/3
1 w.p 1/2
2 w.p 1/6
meaning, with p =1/3 x is equal to 0, with p=1/2 x is equal to 1, and with p=1/6 x is equal to 2.
how can I set a series of Xi random numbers using rand (1,N)?
Thanks In Advance.
0 comentarios
Respuesta aceptada
Más respuestas (1)
Image Analyst
el 26 de Dic. de 2015
Perhaps you mean randi() or randperm() instead of rand(). Anyway, here's one way of many:
N = 1000
% Assign numbers in the specified amounts.
% Assign the 0's.
X = zeros(1,N);
% Assign the 1's.
i1 = round(N/3+1)
i2 = i1 + round(N/2)
X(i1:i2) = 1;
% Assign the 2's.
X(i2+1:end) = 2;
% Now scramble them to give them a random order.
X = X(randperm(length(X)));
% Check distribution to verify.
counts = histogram(X, 'BinMethod', 'Integers', 'Normalization', 'pdf');
0 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!