Replace elements of a vector with different probability for 0 to 1, and 1 to 0
이전 댓글 표시
Hi,
Is there a possibility to replace the zeros in A by 1, and the 1's in A by zero with fixed probability?
For example:
A = [0,1,1,0,1,0,1,0] and I want to replace 0 by 1 with probability 1/4 and 1 by 0 with probability 1/3. Thank you.
답변 (2개)
ES
2013년 9월 30일
0 개 추천
You can use a for loop and counter. Might not be efficient. But still does the trick. Something like this,
for every element in A: if element in A is 0, and count of 0 is ==4:%this is for probability 1/4 A[i]==1; count=0;
Roger Stafford
2013년 9월 30일
You don't need a for-loop. It's a problem in logic.
pdatodo=1/3;
pdotoda=1/4;
r = rand(size(Sent));
Received = (Sent&(r>pdatodo))|(~Sent&(r<=pdotoda));
카테고리
도움말 센터 및 File Exchange에서 Library Development에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!