特征矩阵xi到向量xi的转换



我有一个MatrixXi,比如

[0, 1, 2]
[0, 2, 3]
[4, 7, 6]
[4, 6, 5]
[0, 4, 5]
[0, 5, 1]
[1, 5, 6]

我得到它的一部分,通过这样做:

MatrixXi MR = F.middleRows(first, last);

随意使用。现在我想把这n行变成列向量,比如:

[0, 
1, 
2,
0, 
2, 
3]

可能不使用for循环。我试过:

VectorXi VRT(MR.rows() * MR.cols());
VRT.tail(MR.rows() * MR.cols()) = MR.array();

但是我得到:

Assertion failed: (rows == this->rows() && cols == this->cols() && "DenseBase::resize() does not actually allow to resize."), function resize, file /Users/max/Developer/Stage/Workspace/AutoTools3D/dep/libigl/external/eigen/Eigen/src/Core/DenseBase.h, line 257.

我怎么得到它?我在v4之前使用特征,所以我不能使用重塑…谢谢你

正如chtz指出的那样,这是有效的:

Eigen::VectorXi VR(MR.size());
Eigen::MatrixXi::Map(VR.data(), MR.cols(), MR.rows()) =
MR.transpose();

最新更新