This may sound really noobish, and I’m probably missing something really stupid.. But, I’m trying to calculate the differences between matrices, and the one with the smallest value (result) is the matching number.. But, for some reason my algorithm seems to be missing the smallest number and I can’t figure out why..
Here is the code:
int min_val = 0;
double comp = 0;
const int ROW_BOUNDS(mat1Rows-mat2Rows+1);
const int COL_BOUNDS(mat1Cols-mat2Cols+1);
for(int i=0; (i < ROW_BOUNDS); i++) {
for(int j=0; (j < COL_BOUNDS); j++) {
m3.clear();
for (int row(0); row < mat2Rows; row++){
for (int col(0); col < mat2Cols; col++){
//cout << matrix1[i*mat1Cols+row*mat1Cols+col+j] << ' ';
m3.push_back( matrix1[i*mat1Cols+row*mat1Cols+col+j] );
currentRow = i;
currentCol = j;
}
}
comp = compMatrix1(matrix2, m3);
//printMatrix(m3, 2, 2);
//cout << endl << " = " << comp << endl;
if(comp < min_val)
{
minRow = currentRow;
minCol = currentCol;
m4 = m3;
min_val = comp;
cout << min_val;
}
}
}
//printMatrix(m4, 2, 2);
And here is the output:
0 0
0 0
= 2
0 1
0 1
= 4
1 0
1 0
= 0
0 0
1 1
= 2
0 1
1 1
= 3
1 0
1 0
= 0
1 1
0 1
= 3
1 1
1 0
= 1
1 0
0 0
= 1
It prints:
0 0
0 0
When the actual result should be:
1 0
1 0
Could anyone offer any help please?
few questions:
what does compMatrix1 look like? What is matrix2?
Also can you explain what the following code does?
You may just be comparing matrices improperly or not filling m3 correctly. Also,
Initializes the minimum value to be a lower than some values. What happens when the lowest value is actually 2? Then no matrix will have the min_val.