Probability in random numbers!

조회 수: 10 (최근 30일)
Mina Mansour
Mina Mansour 2019년 8월 5일
편집: Adam Danz 2019년 8월 7일
How to create a random 2D array that each cell has different probabilities to be either 0 or 1 for example? In other words, how to t create a 2D array with each cell having a probability of 0.1 to be 1's and 0.9 probability to be 0's.

답변 (2개)

Walter Roberson
Walter Roberson 2019년 8월 5일
rand(m, n) <= 0.1
would be true (1) with probability 0.1

Adam Danz
Adam Danz 2019년 8월 5일
편집: Adam Danz 2019년 8월 7일
randsrc(5,4,[[0,1];[.9,.1]])
% 5 x 4 array
% .9 prob. of 0
% .1 prob of 1
*Requires communications toolbox
  댓글 수: 3
Mina Mansour
Mina Mansour 2019년 8월 6일
It keeps on telling me I need a communications toolbox.
Adam Danz
Adam Danz 2019년 8월 6일
Use Walter Roberson's answer if you don't have communications toolbox.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by