Eigen::Matrix 转 std::vector 亲测ok!


    std::vector data;
    for (int kk = 0; kk < 24; kk++) {
        data.push_back(kk);
    }

    int n = 24 / 3;
    typedef Eigen::Matrix MatrixXd;

    //vector 转 matrix
    Eigen::Map result(data.data(), 3, n);

    //matrix 转 vector 
    std::vector out(&result(0, 0), result.data() + result.cols()*result.rows());
    

    std::cout << data << std::endl;
    std::cout << result << std::endl;
    std::cout << out << std::endl;

结果:

0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23


 0  3  6  9 12 15 18 21
 1  4  7 10 13 16 19 22
 2  5  8 11 14 17 20 23


0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23

你可能感兴趣的:(c++,算法,开发语言)