Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7842105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:14:33+00:00 2026-06-02T16:14:33+00:00

This may sound really noobish, and I’m probably missing something really stupid.. But, I’m

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T16:14:34+00:00Added an answer on June 2, 2026 at 4:14 pm

    few questions:

    comp = compMatrix1(matrix2, m3); 
    

    what does compMatrix1 look like? What is matrix2?

    Also can you explain what the following code does?

    m3.push_back( matrix1[i*mat1Cols+row*mat1Cols+col+j] );
    

    You may just be comparing matrices improperly or not filling m3 correctly. Also,

    int min_val = 0;
    

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This may sound like a stupid question, perhaps it is. But I'm only trying
This may sound really stupid. but I've got a strange problem with the D
I'm trying to studdy some performace things... this question may sound stupid, but I'll
I know this may sound stupid, but i really want to know :) im
This may sound really stupid but I have to ask cause I'm not finding
This may sound stupid but... When I create big SQL commands I want to
This may sound like a stupid question but I'm a beginner not just to
this may sound funny, but i spent hours trying to recreate a knob with
This may sound very noobish but I have tried to read the forum posts
This may sound stupid but how do I define a global variable in Go?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.