maximum, minimum and average of a matrix?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: maximum, minimum and average of a matrix?

  1. #1
    Join Date
    Feb 2011
    Posts
    7

    Unhappy maximum, minimum and average of a matrix?

    std::vector<std::vector<unsigned long> > matrix(15); // 15 rows
    typedef std::vector<std::vector<unsigned long> >::iterator it_type;

    it_type row = matrix.begin();

    for (int w=0;w<10;w++)
    {
    //some lines of code
    unsigned long num = x.to_ulong();
    cout <<"Decimal form is: " << num<< end;
    // if we've hit 15 items in the current row (i.e. 15 columns), then shift to the next row
    if (row->size() == 15)
    ++row;

    // add this to the next column in the current row
    row->push_back(num);
    }
    // resize the last row
    row->resize(15); // this will ensure that there are 15 columns in the last row


    for(size_t i=0; i < matrix.size(); ++i)
    {
    for(size_t j=0; j < matrix[i].size(); ++j)
    cout << matrix[i][j] << " ";
    cout << endl;
    }

    Now I want to find maximum, minimum and average of this matrix. What shall I do?

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,545

    Re: maximum, minimum and average of a matrix?

    Victor Nijegorodov

  3. #3
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: maximum, minimum and average of a matrix?

    Iterate through the elements of the matrix and compare each against a reference value and if necessary update the reference value.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  4. #4
    Join Date
    Feb 2011
    Posts
    7

    Re: maximum, minimum and average of a matrix?

    how? can you explain a little?

  5. #5
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,545

    Re: maximum, minimum and average of a matrix?

    Can you find maximum, minimum and average of the elements being in a plain integer array?
    Victor Nijegorodov

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center