Probability in random numbers!

1 visualizzazione (ultimi 30 giorni)
Mina Mansour
Mina Mansour il 5 Ago 2019
Modificato: Adam Danz il 7 Ago 2019
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.

Risposte (2)

Walter Roberson
Walter Roberson il 5 Ago 2019
rand(m, n) <= 0.1
would be true (1) with probability 0.1

Adam Danz
Adam Danz il 5 Ago 2019
Modificato: Adam Danz il 7 Ago 2019
randsrc(5,4,[[0,1];[.9,.1]])
% 5 x 4 array
% .9 prob. of 0
% .1 prob of 1
*Requires communications toolbox
  3 Commenti
Mina Mansour
Mina Mansour il 6 Ago 2019
It keeps on telling me I need a communications toolbox.
Adam Danz
Adam Danz il 6 Ago 2019
Use Walter Roberson's answer if you don't have communications toolbox.

Accedi per commentare.

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by