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.

2 Answers

Just use operator=:

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

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.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.