Vector of vectors - accessing the column vector

Hello,

I am using the <vector> class to define a matrix (or rather a list of vectors) as follows:

typedef vector<double> Vec;
typedef vector<Vec> Mat;

Mat A;

Once I have initialized my matrix A - I find it very easy to access each row vector of A. The first one is

A[0]

the problem is how do I access the column vector?

More details:

I have a function

Vec operator*(const Mat& a, const Coeffs& x)
{
unsigned long i,j,k;
unsigned long m = a.size();
unsigned long n = x.size();

Vec prod(m);

for(i = 0; i < m; i++)
{
prod[i] = 0.0;
for(k = 0; k < n; k++)
{
j=x[k].name;
prod[i] += a[i][j]*x[k].val;
}
}
return prod;
}

where I have that

enum variables {age,sex,race,health,dotproduct};

struct Coeff
{
variables name;
double val;
};

typedef vector<Coeff> Coeffs;

and I have defined

Coeffs coeff(2);
coeff[0].name=age;
coeff[0].val=1;
coeff[1].name=health;
coeff[1].val=2;

The following works fine:

Vec b = A*coeff;

but what I want is something like

A[][dotproduct] = A*coeff;

Thus I need to be able to access the column vector called dotproduct in the matrix A.

I can of course solve this using loops- but is there a more elegant and possibly faster way?

Thanks,

Raff.
Perhaps a more elegant way would be to use boost::multi_index_container, but that is probably beyond your scope.

Having said that, there really isn't a convenient way.
Topic archived. No new replies allowed.