create Non-uniform distribution
이전 댓글 표시
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.
채택된 답변
추가 답변 (1개)
Image Analyst
2015년 12월 26일
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');
카테고리
도움말 센터 및 File Exchange에서 Uniform Distribution (Continuous)에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!