how can I generate a discrete random number from 3 possible numbers in matlab. Ex I want to choose ( 0 or 1 or -1)
Follow Math Help Forum on Facebook and Google+
Hello, Originally Posted by florezl how can I generate a discrete random number from 3 possible numbers in matlab. Ex I want to choose ( 0 or 1 or -1) Well, you could define u=rand() and then, [if u<1 [if u<2/3 [if u<1/3, x=-1] x=0] x=1]. (rand() gives a value between 0 and 1)
Last edited by Moo; March 18th 2009 at 02:52 PM. Reason: changed a bit the text
View Tag Cloud