Search code examples
c++eigen

How can I convert the last column in svd.MatrixV() to 3 by 3 matrix?


I have obtained the 9th column in V matrix of singular value decomposition using:

svd.matrixV().array().col(8)

The column consists of 9 elements. 3.6 -0.0148 -1.922 -4.177 0.0135 -0.00389 -2.29 -0.98 0.21

Is there away in Eigen that can convert the 9 element column of svd.MatrixV() to 3 by 3 matrix ?


Solution

  • You can do so using an Eigen::Map as follows:

    Eigen::Map<Eigen::MatrixXf> col_map {svd.matrixV().array().col(8).data(), 3, 3};
    

    This map can then be assigned to a new matrix

    Eigen::MatrixXf col_mat {col_map};