0

I'm having trouble dividing two elements of an array.... it seems to work in some instances, but not right now... I have two matrices[row][col] sized and am trying to transpose the elements to a matrix to a vector/array. That all works fine... but when I then try to divide the elements by a ratio it all buckles down....

```
double total[col];
double ratio[col];
for(i=0;i<col;i++){
total[i]=0;
ratio[i]=0; }
for(i=0; i<col; i++){
for(j=0;j<row;j++){
total[i]=total[i]+matrix[j][i];
}
printf("total %f\n",total[i]);
}
....
printf("min %f",min);
// Ratio time...
for(i=0;i<col;i++){
ratio[i]=total[i]/min;
printf("%f ratio \n",ratio[i]);
}
// Change matrix into an array as received by R for compatibility.
c=0;
for(i=0;i<row;i++){
for(j=0;j<col;j++){
matrix2[i][j]=matrix[i][j]; // Create a copy...
printf("matrix %f \n",matrix2[i][j]);
c++;
}
}
c=0;
for(i=0;i<col;i++){
for(j=0;j<row;j++){
pmatrix[c]=matrix2[j][i];
printf("pmatrix %f \n",pmatrix[c]);
c++;
}
}
counter = 0;
j=-1;
for (i=0; i<size; i++) {
if (counter % row == 0) {
j++;
}[B]
pmatrix[i]=pmatrix[i]/ratio[j];[/B]
printf("pmatrix %d after ratio: %f \n",i,pmatrix[i]);
counter++;
}
```

sometimes, if I divide pmatrix* by ratio [j] TWICE then it comes out with the correct value for dividing the first time...*

The issue in particular is :

pmatrix*=pmatrix /ratio[j];*

When I do it twice, and row ==2, it works... when I leave it as is, and row == 13 it works fine....

*Edited 6 Years Ago by nosson*: clarity