+ Post New Thread
Results 1 to 6 of 6

13th February 2019, 11:04 #1
 Join Date
 Jan 2016
 Posts
 48
 Helped
 0 / 0
 Points
 856
 Level
 6
Generate random sequence of 1's and 1's in matlab
How do i generate a random sequence of 1's and minus 1's in matlab with mean 0?

Advertisement

13th February 2019, 12:08 #2
 Join Date
 Oct 2006
 Location
 Real Homeless
 Posts
 2,396
 Helped
 644 / 644
 Points
 15,719
 Level
 30
Re: Generate random sequence of 1's and 1's in matlab
Code:x0 = 1:40; y0 = 2*int32( randn( size(x0) ) >= 0.0 )  1;

Advertisement

18th May 2019, 14:27 #3
 Join Date
 Jan 2016
 Posts
 48
 Helped
 0 / 0
 Points
 856
 Level
 6
Re: Generate random sequence of 1's and 1's in matlab
This doesnt always give a mean of zero

Advertisement

18th May 2019, 14:50 #4
 Join Date
 Jan 2019
 Posts
 254
 Helped
 49 / 49
 Points
 1,257
 Level
 8
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

18th May 2019, 15:02 #5
 Join Date
 Jan 2008
 Location
 Bochum, Germany
 Posts
 44,740
 Helped
 13608 / 13608
 Points
 256,485
 Level
 100
Re: Generate random sequence of 1's and 1's in matlab
This doesnt always give a mean of zero
You may want to specify additional properties of the random distribution, e.g. maximal imbalance for a given sample length.

Advertisement

18th May 2019, 17:31 #6
+ Post New Thread
Please login