i want to have a binary generator with the equal probalbility for 0 and1 and i dont know how to wite and even help didn't help me

댓글 수: 1

pars abd
pars abd 2011년 5월 29일
and what is n because it turns red with an error on n...

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

 채택된 답변

James Tursa
James Tursa 2011년 5월 28일

2 개 추천

See the rand function. There are various ways to get 0 1 results depending on what you are doing with it downstream. Do you want a double result or a logical result? e.g., logical result could use
rand(n,1)<.5
Or a double result could use
floor(rand(n,1)*2)

댓글 수: 5

Matt Fig
Matt Fig 2011년 5월 28일
Or:
round(rand(n,1))
Jan
Jan 2011년 5월 28일
Another method for DOUBLEs: +(rand(n, 1) < 0.5)
Paulo Silva
Paulo Silva 2011년 5월 29일
another one
randi([0 1],n,1)
pars abd
pars abd 2011년 5월 29일
what is n and what is the answer
what should i see?
Paulo Silva
Paulo Silva 2011년 5월 29일
n is the number of bits you want to generate, you can replace the n in your code or assign a value to it before generating the bits
n=10; %generates 10 bits

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 MATLAB Coder에 대해 자세히 알아보기

질문:

2011년 5월 28일

Community Treasure Hunt

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

Start Hunting!

Translated by