Eigen::MatrixXd m(3,3); m << 1,2,3, 4,5,6, 7,8,9; Eigen::VectorXd col2 = m.col(1); //accessing the second column of matrix m std::cout << "The second column of m:\n" << col2 << std::endl;
The second column of m: 2 5 8
Eigen::MatrixXd m(3,3); m << 1,2,3, 4,5,6, 7,8,9; Eigen::VectorXd new_col(3); new_col << 10,11,12; m.col(1) = new_col; //assigning new_col to the second column of m std::cout << "The updated matrix m:\n" << m << std::endl;
The updated matrix m: 1 10 3 4 11 6 7 12 9
Eigen::MatrixXd m(3,3); m << 1,2,3, 4,5,6, 7,8,9; m.col(2) = m.col(0) + m.col(1); //adding first and second columns and storing in the third column std::cout << "The updated matrix m:\n" << m << std::endl;
The updated matrix m: 1 2 3 4 5 9 7 8 15Eigen Matrix library is a C++ template library for linear algebra: matrix and vector operations, numerical solvers, and related algorithms.