#includeusing namespace Eigen; int main() { MatrixXd mat(3, 3); mat << 1, 2, 3, 4, 5, 6, 7, 8, 9; MatrixXd cols_mat = mat.cols(0, 2); return 0; }
#includeThis example creates a 3x3 matrix, and extracts the 2nd and 3rd columns (1 to 2) into a new matrix called `cols_mat`. It then prints both matrices to the console. Package library: Eigen.#include using namespace Eigen; int main() { MatrixXd mat(3, 3); mat << 1, 2, 3, 4, 5, 6, 7, 8, 9; std::cout << "Original matrix:\n" << mat << std::endl; MatrixXd cols_mat = mat.cols(1, 2); std::cout << "Matrix of columns 1 and 2:\n" << cols_mat << std::endl; return 0; }