select numbers based on different probabiltiies
Mostrar comentarios más antiguos
I have an event that happens at a prbability of 1E-06. I want Matlab to return me 1 if that event happens and 0 otherwise. Rand gives me a number upto four decimal places. Could you folks help me come up with a solution.
Thank you
4 comentarios
Bruno Luong
el 4 de Dic. de 2018
Editada: Bruno Luong
el 4 de Dic. de 2018
Rand gives me a number upto four decimal places
Nope RAND returns double, i.e., more than 15 significant decimals.
Don't be fool by what display on your screen and what is stored internally.
messi
el 4 de Dic. de 2018
Image Analyst
el 4 de Dic. de 2018
Editada: Image Analyst
el 4 de Dic. de 2018
Yes. But you don't need the ran=rand line if you're never going to use ran. To see more digits:
format longG
Bruno Luong
el 4 de Dic. de 2018
Editada: Bruno Luong
el 4 de Dic. de 2018
No this code returns 1 with 1e-5 probability chance, not 1e-6 as you have stated.
ran = rand;
if (rand<1E-05)
selec=1;
else
selec=0;
end
Respuesta aceptada
Más respuestas (1)
messi
el 4 de Dic. de 2018
0 votos
Categorías
Más información sobre Whos en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!