Ran
Ran

Reputation: 4157

Eigen - get a matrix from a map?

I'm using Eigen::Map to get access to create an object from a C-array. I would like to save that object as a member variable of type MatrixXf.

How do I do that? I couldn't find a way to convert the Map to a Matrix.

Thanks.

Upvotes: 9

Views: 10691

Answers (2)

GPrathap
GPrathap

Reputation: 7810

I have encountered the same issue but vector is constant, then you have to do it following way as @ggael proposed,

Eigen::MatrixXd mat = Eigen::Map<const Eigen::MatrixXd>(x.data(), rows, cols);

where x can be either const Eigen::VectorXd x or const std::vector<double> or C type array.

Upvotes: 2

ggael
ggael

Reputation: 29205

Just use operator=:

MatrixXd mat;
mat = Map<MatrixXd>(data, rows, cols);

Upvotes: 12

Related Questions