Eigen Convert Matrix to Vector

前端 未结 3 1943
独厮守ぢ
独厮守ぢ 2021-01-04 12:41

In MATLAB, the line below converts a Matrix to a Vector.It flattens the matrix column by column into a vector.

myvar(:)

Ho

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-04 13:26

    Another way to do it is:

    ...
    VectorXd B = A;
    B.resize(B.cols()*B.rows(), 1);
    

    or, if you want the vector in row order:

    ...
    VectorXd B = A.transpose();
    B.resize(B.cols()*B.rows(), 1);
    

    Regards.

提交回复
热议问题