To resolve issues starting MATLAB on Mac OS X 10.10 (Yosemite) visit: http://www.mathworks.com/matlabcentral/answers/159016
So the follwoing for loop will generate 8133 random values for 'astrosRuns' between the possible range of (0:16). The random values for 'astrosRuns' are generated depending upon the random values of either 'j' or 'k'.
There are 8133 steps in this for loop. I want to add the constraint that the average of every group of 10 'astroRuns' values equals 4. (that's the average in values not the sum) Meaning that a group of ten values could possibly be: (1,4,6,6,2,2,9,4,2,4). These ten steps have an average in values of 4. And then the next group of 10 values must also have an average in values of 4 however, it could be a different combination in values like: (8,5,7,4,0,0,1,4,5,6).
Here is the example code:
for i=1:8133; % Let j = the probability for the score value % Let k = the probability that the adjacent values will be equal % j =rand; k =rand;
if 0<=k<=.0063 astrosRuns(i+1)=astrosRuns(i);
elseif 0<=j<=.0687 astrosRuns(i+1)=0;
elseif .0688<=j<=.1880 astrosRuns(i+1)=1;
elseif .1881<=j<=.3286 astrosRuns(i+1)=2;
elseif .3287<=j<=.4801 astrosRuns(i+1)=3;
elseif .4802<=j<=.6110 astrosRuns(i+1)=4;
elseif .06111<=j<=.7223 astrosRuns(i+1)=5;
elseif .7224<=j<=.8050 astrosRuns(i+1)=6;
elseif .8051<=j<=.8696 astrosRuns(i+1)=7;
elseif .8697<=j<=.9156 astrosRuns(i+1)=8;
elseif .9157<=j<=.9455 astrosRuns(i+1)=9;
elseif .9456<=j<=.9671 astrosRuns(i+1)=10;
elseif .9672<=j<=.9797 astrosRuns(i+1)=11;
elseif .9798<=j<=.9874 astrosRuns(i+1)=12;
elseif .9875<=j<=.9931 astrosRuns(i+1)=13;
elseif .9932<=j<=.9962 astrosRuns(i+1)=14;
elseif .9963<=j<=.9984 astrosRuns(i+1)=15;
else .9985<=j<=1; astrosRuns(i+1)=16; end end
So basically, I want to have the values for 'astrosRuns' randomly created but also follow a law of average of 4.
I hope this is clearer now. Thanks for all the help!
No products are associated with this question.
This could be written without the for-loop or the if-statement by using histc.
x = rand(8033,1); edges = [0,.0687,.1880] %etc. for all of yoru values
[~, astroRuns] = histc(x,edges); %edited!
for how this works. Also, to find out why what you are doing now does not work: