create Non-uniform distribution
Mostrar comentarios más antiguos
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.
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');
Categorías
Más información sobre Uniform Distribution (Continuous) en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!