Prob Matrix for binary sequence
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
for some integer 'n', I have a matrix M of size (2^n) x n containing all possible binary sequences. Another vector N of length 'n' that contains the probabilities of bit being zero. I want to compute the prob of each sequence without using for loops.
Example
n=2;
M = [0 0;0 1;1 0;1 1];
N = [Prob(N1=0)=0.3 Prob(N2=0)=0.2]
Prob(M1M2=00) = (0.3)*(0.2)
Prob(M1M2=01) = (0.3)*(1-0.2)
Prob(M1M2=10) = (1-0.3)*(0.2)
Prob(M1M2=11) = (1-0.3)*(1-0.2)
0 comentarios
Respuestas (1)
Matt J
el 15 de Mzo. de 2013
Probabilities = prod(bsxfun(@times,M,1-N) +bsxfun(@times,~M,N),2);
3 comentarios
Walter Roberson
el 15 de Mzo. de 2013
Note that the character before the M is the tilde, not subtraction.
Ver también
Categorías
Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!