[英]Eigen - get a matrix from a map?
I'm using Eigen::Map to get access to create an object from a C-array.我正在使用 Eigen::Map 来访问从 C 数组创建对象。 I would like to save that object as a member variable of type MatrixXf.
我想将该对象保存为 MatrixXf 类型的成员变量。
How do I do that?我怎么做? I couldn't find a way to convert the Map to a Matrix.
我找不到将 Map 转换为 Matrix 的方法。
Thanks.谢谢。
Just use operator=
:只需使用
operator=
:
MatrixXd mat;
mat = Map<MatrixXd>(data, rows, cols);
I have encountered the same issue but vector is constant, then you have to do it following way as @ggael proposed,我遇到了同样的问题,但向量是恒定的,那么你必须按照@ggael 建议的方式来做,
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.其中 x 可以是
const Eigen::VectorXd x
或const std::vector<double>
或 C 类型数组。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.