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 comentario

pars abd
pars abd el 29 de Mayo de 2011
and what is n because it turns red with an error on n...

Iniciar sesión para comentar.

 Respuesta aceptada

James Tursa
James Tursa el 28 de Mayo de 2011

2 votos

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 comentarios

Matt Fig
Matt Fig el 28 de Mayo de 2011
Or:
round(rand(n,1))
Jan
Jan el 28 de Mayo de 2011
Another method for DOUBLEs: +(rand(n, 1) < 0.5)
Paulo Silva
Paulo Silva el 29 de Mayo de 2011
another one
randi([0 1],n,1)
pars abd
pars abd el 29 de Mayo de 2011
what is n and what is the answer
what should i see?
Paulo Silva
Paulo Silva el 29 de Mayo de 2011
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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre MATLAB Coder en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 28 de Mayo de 2011

Community Treasure Hunt

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

Start Hunting!

Translated by