std::vector<double> data;for (int kk = 0; kk < 24; kk++) {data.push_back(kk);}int n = 24 / 3;typedef Eigen::Matrix<double, 3, Eigen::Dynamic> MatrixXd;//vector 转 matrixEigen::Map<Eigen::MatrixXd> result(data.data(), 3, n);//matrix 转 vector std::vector<double> 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