Good Afternoon,
I am working on a project in which I would need to create a matrix of nxm dimensions, in which the top, bottom, left and right edges should have the value 1 and the interior of the matrix should be a random between 0 and 1 with a give probability. I`ve tried to write the following code but when I try to create the interior it gives an error.
Here is the code:
void create_edges(){
matrix_save = new int*[dim1_save];//allocate the space for an array of pointers
for(int i=0; i<dim1_save; i++){//for each of those pointers, allocate the
matrix_save[i] = new int[dim2_save];//amount of space we need
}
//matrix_save=(bool)matrix_save;
for(int i=0;i<dim1_save;i++){
for (int j=0;j<dim2_save;j++){
if ((j==0) && (i<dim1_save))
matrix_save[i][j]=1;
else if ((i==0) && (j<dim2_save))
matrix_save[i][j]=1;
else if ((i==dim1_save-1)&&(j<dim2_save))
matrix_save[i][j]=1;
else if ((i<dim1_save-1)&&(j==dim2_save-1))
matrix_save[i][j]=1;
else matrix_save[i][j]=0;
}
}
}
void init_matrix(){
int aux;
int count=0;
srand((unsigned)time(NULL));
int lowest=0, highest=100;
int range=(highest-lowest)+1;
aux=lowest+int(range*rand()/(RAND_MAX + 1.0));
for(int i=1;i<=dim1_save;i++){
for (int j=1;j<=dim2_save;j++){
if(aux<=100-complexity)
matrix_save[i][j]= 0;
else {
matrix_save[i][j]= 1;
count=count+1;
}
}
}
cout<<count;
system("PAUSE");
}
Please Help me