I'm trying to make a selection process using roulette wheel selection. To do this I created two matrix, one random probabilities and one increasing probabilities. The idea is to choose a number according to the random probabilities. Here is the code I've written.
while(c<10){
if (select[z]-prob[c]<0){
mat [z]=c;
z++;
}
c++;
}
mat array can only take 5 items, but your while loop runs 10 times, which means that after a while, the elements of the array will start to get overwritten.
Maybe you want to have it like this?
1 2 3 4 5 6 7 8 9 10
while (z<10){
c=0;
while(c<5){
if (select[z]-prob[c]<0){
mat [z]=c;
c++;
}
z++;
}
}
FIXED:
1 2 3 4 5 6 7 8 9 10
while (z<10){
c=0;
while(c<5){
if (select[c]-prob[z]<0){
mat [c]=z;
c++;
}
z++;
}
}