How to generate random number from Bernoulli distribution?

조회 수: 73 (최근 30일)
PARVATHY NAIR
PARVATHY NAIR 2023년 1월 19일
답변: Bruno Luong 2023년 1월 19일
just like the below command
a=randn(1,1000)
how can we generate random number from bernoulli distribution

채택된 답변

Bruno Luong
Bruno Luong 2023년 1월 19일
p = 0.25
p = 0.2500
X = double(rand(1,1000) < p)
X = 1×1000
0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 1 0 1 0 1 0 0 0 1 0 1 0 0 0
histogram(X,'Normalization','pdf')

추가 답변 (0개)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by