Reputation: 323
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'.
Upvotes: 5
Views: 2940
Reputation: 4542
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();
Upvotes: 6