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?

The symbols ROW_BOUNDS and COL_BOUNDS are macros? If so, please post their definitions (in their entirety) here. Also, you are missing other code, such as where mat1rows, et al are declared and defined. IE, you need to post the function declaration that you are calling here, as well as the code that calls it. Giving us less than half of the necessary information makes it difficult to help...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.