Home > database >  Eigen MatrixXi to VectorXi conversion
Eigen MatrixXi to VectorXi conversion

Time:12-20

I have a MatrixXi, say

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

I get a part of it by doing:

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

with first and last at will. Now I'd like to turn those n rows into a column VectorXi, like:

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

possibly without using a for loop. I've tried:

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

But I get:

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.

How do I get that? I'm using Eigen before v4 so I cannot use reshape... Thank you

CodePudding user response:

As pointed out by chtz, this works:

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