Prob Matrix for binary sequence

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)

답변 (1개)

Matt J
Matt J 2013년 3월 15일

0 개 추천

Probabilities = prod(bsxfun(@times,M,1-N) +bsxfun(@times,~M,N),2);

댓글 수: 3

Using the above expression gives Probabilities =
0.5600
-0.5600
-0.5600
0.5600
whereas the desired result is 0.0600 0.1400 0.2400 0.5600
Matt J
Matt J 2013년 3월 15일
편집: Matt J 2013년 3월 15일
Not for me. I get the correct values.
>> M = [0 0;0 1;1 0;1 1];N=[0.3,0.2]; Probabilities = prod(bsxfun(@times,M,1-N) +bsxfun(@times,~M,N),2)
Probabilities =
0.0600
0.2400
0.1400
0.5600
Walter Roberson
Walter Roberson 2013년 3월 15일
Note that the character before the M is the tilde, not subtraction.

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

카테고리

도움말 센터 및 File Exchange에서 Operating on Diagonal Matrices에 대해 자세히 알아보기

질문:

2013년 3월 14일

Community Treasure Hunt

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

Start Hunting!

Translated by