Generate random sequence of 1's and -1's in matlab

Status
Not open for further replies.

Chinmaye

Full Member level 3
Joined
Jan 18, 2016
Messages
164
Helped
0
Reputation
0
Reaction score
1
Trophy points
1,298
Activity points
3,145
How do i generate a random sequence of 1's and minus -1's in matlab with mean 0?
 

This doesnt always give a mean of zero
 

Re: generate random 1's and -1's in matlab

the rand function generates uniformly distributed random numbers

if you tell it to generate random numbers between 0 and 1,
you can convert those less than 0.5 to -1 and those greater than 0.5 to 1
 

This doesnt always give a mean of zero
By nature of random distribution, an arbitrary selected sample can't have exactly zero mean otherwise it's not random.

You may want to specify additional properties of the random distribution, e.g. maximal imbalance for a given sample length.
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…