This is the basic C++ program of C++ armadillo library which shows how to access rows and column of the given matrix. It can be carried out by the help of inbuilt functions "row" or "col" in armadillo library. Both thefunction do not take any parametres. Elements can be made zero by function "zeros".
mat A = randu<mat>(4,4); //random matrix of size 4x4 (generared by this syntax)
cout << "Matrix A::\n"<<endl;
cout<< A << endl;
// Accessing first row of matrix A
cout << "Row 1::\n"<<endl;
cout << A.row(0) << "\n"; //Displaying first row
A.row(0) = A.row(1) + A.row(3); //Addition of rows
cout << "Matrix A(After operation)::\n"<<endl;
cout<< A << endl;
// Accessing second column of matrix A
cout << "Column 2::\n"<<endl; //Displaying second column
cout << A.col(1) << "\n";
// Making all the elements of third column of matrix A to zero
A.col(2).zeros(); //Making all the elements zero
cout << "Matrix A(After operation)::\n"<<endl;
cout<< A << endl;
Comments