How to assign probability to a matrix element?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Daniel Maia
am 11 Dez. 2013
Bearbeitet: Roger Stafford
am 11 Dez. 2013
Hi,
was wondering if somebody know to do the following:
I want to generate a matrix of zeros and ones with some probability of an element being zero or one. For instance:
Let A be a matrix, then
A(i,j) = 1 with probability p; A(i,j) = 0 with probability 1-p;
for some i,j and 0<p<1.
Is there a function on matlab which I can use to fo this?
0 Kommentare
Akzeptierte Antwort
Weitere Antworten (1)
Roger Stafford
am 11 Dez. 2013
Bearbeitet: Roger Stafford
am 11 Dez. 2013
It isn't clear whether the elements' probabilities are all to be equal to a single value, p, or each element A(i,j) is to have its own individual probability p(i,j). If you mean the latter, let P be a matrix the same size as A in which an element p(i,j) is the probability that A(i,j) is 1, and otherwise it is to be 0. Do this:
A = rand(size(P))<=P;
0 Kommentare
Siehe auch
Kategorien
Mehr zu Assembly finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!