Find size of MatDoub


totally_noob
04-17-2008, 11:17 AM
Hi all,

I am a total beginner so please don't be hating.

How do I add size() to the MatDoub typedef (or NRMatrix template) so that I can just do this:

void display (const MatDoub & vy)
{ for (int i = 0; i < vy.size(); i++) // loops through each row of vy
{ for (int j = 0; j < vy[i].size(); j++) // loops through each element of each row
cout << vy[i][j] << " "; // prints the jth element of the ith row
cout << endl;
}

sorry for being a lamer!
Cheers

davekw7x
04-17-2008, 02:12 PM
How do I...

The definition of the NRmatrix class (look in nr3.h) has member functions for the number of rows and the number of columns:


#include "../code/nr3.h"

void showsize(const MatDoub & mat);

int main()
{
int m = 20;
int n = 30;
MatDoub m1(2, 3);
MatDoub m2(n, m);

cout << "Calling showsize for m1: " << endl;
showsize(m1);

cout << "Calling showsize for m2: " << endl;
showsize(m2);

return 0;
}

void showsize(const MatDoub & mat)
{
cout << " In showsize(): "
<< "Number of rows = " << mat.nrows()
<< ", Number of cols = " << mat.ncols() << endl << endl;
}


Output:

Calling showsize for m1:
In showsize(): Number of rows = 2, Number of cols = 3

Calling showsize for m2:
In showsize(): Number of rows = 30, Number of cols = 20


Regards,

Dave

totally_noob
04-18-2008, 03:23 AM
Many thanks!