3

I'm using eigen matrix library.

How can I convert a matrix of 1* 1 to a number(float or others)?

It's OK to do this

cout << ((MatrixXf(1,2) << 0, 2).finished()) * ((MatrixXf(2,1) << 0, 2).finished()) << endl;

But when I try to do this

MatrixXf mtemp(2,1);
mtemp(0,0) = ((MatrixXf(1,2) << 0, 2).finished()) * ((MatrixXf(2,1) << 0, 2).finished());

It said 'cannot convert const Eigen::GeneralProduct to float in assignment'.

4

1 回答 1

3

If mat is an 1-by-1 matrix, then mat.value() is its only entry as a scalar.

Thus, you can do

mtemp(0,0) = (((MatrixXf(1,2) << 0, 2).finished()) 
              * ((MatrixXf(2,1) << 0, 2).finished())).value();
于 2012-05-14T08:57:23.320 回答