问题描述
在eigen c ++中,你如何
将一个vectorXf映射到一个matrixXf
(适当的维度)
href =http://eigen.tuxfamily.org/dox/TutorialMapClass.html =nofollow> docs 在
如何做到外部对象
所以我知道我们可以:
MatrixXf x_cen = Map< MatrixXf>(* x,* n,* p);
/ p>
但是如果 x
是 VectorXf
p>
可以使用.data()成员函数,后跟Map:
VectorXf vec(rows * cols);
vec = ...;
Map< MatrixXf> vec_view_as_a_matrix(vec.data(),rows,cols);
然后你可以像任何Eigen对象一样使用vec_view_as_a_matrix,vec_view_as_a_matrix的修改也会报告给vec如果你想复制到一个新的MatrixXf对象,那么使用你写的结构:
MatrixXf x_cen = Map< MatrixXf>(vec.data(),rows,cols);
In eigen c++, how do you map a vectorXf to a matrixXf (of appropriate dimensions)
(there is good docs on how to do it for external objects so i know we can do:
MatrixXf x_cen=Map<MatrixXf>(*x,*n,*p);
but what if x
is a VectorXf
?
You can use the .data() member function followed by Map:
VectorXf vec(rows*cols);
vec = ...;
Map<MatrixXf> vec_view_as_a_matrix(vec.data(), rows, cols);
Then you can use vec_view_as_a_matrix just like any Eigen objects, modifications to vec_view_as_a_matrix will be reported to vec as well since they are sharing the memory. If you want to copy to a new MatrixXf object, then use the construction you wrote:
MatrixXf x_cen = Map<MatrixXf>(vec.data(), rows, cols);
这篇关于eigen :: vectorXf到MatriXf映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!