Search code examples
c++matrixvectoreigeneigenvector

How to get an Eigen vector from an Eigen matrix column/row?


The thing I want to do is this:

MatrixXd M;
// Whatever assigned to `X`
VectorXd V = M(1);

Eigen does not support this. Is there a way to retrieve an Eigen vector from an Eigen matrix?


Solution

  • Eigen Slicing and Indexing is of much use here.

    To retrieve an i-th row vector:

    VectorXd V = M(i, all);
    

    To retrieve an i-th column vector:

    VectorXd V = M(all, i);