This has had me stumped all day. Any help is appreciated. I'm trying to do the following with an array:
1.) randomly populate an array called 'astrosRuns' with 8133 values.
2.) the possible values to populate the 'astrosRuns' array with range in values (0:16)
3.) I want each possible value of that range to have a specific probability of occurring.
4.) I also want to establish the constraint that every group of 10 values within the 'astrosRuns' array has an average value of 4.
I'm a beginner so I've developed some code (which is probably very inefficent) to attempt to tackle goals 1,2, and 3 from above. I'm totally clueless how to do 4.
What i've done so far is construct a for loop for the 8133 steps and made a bunch of if else if statements for the probabilities of each value between the range of (0:16) occurring.
How would I then also have the program adhere to another constraint (or bias) that every unique group of 10 values will combine to have an average value of 4 (or in essence a sum of 40)
So..the first 10 values could be (8,5,7,4,0,0,1,4,5,6) which has an avearge of 4. But the program will be smart enough to generate the 8133 values within the array to adhere to the given probabilities 'j' AND the 10 value average rule of 4.
here's my code so far:
% This for loop begins calculating the probabilities for the occurence of a given score. I set this up as a range between values that were taken from the histogram. I had to do this manually since I don't know an easier way yet. 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
ANY help is most appreciated. Please keep in mind that I'm a beginner...so if you could please explain any answers with a TON of detail..I just might understand. Please answer as if I'm the dumbest programmer you've ever met!
No products are associated with this question.
Play games and win prizes!Learn more