How to access a specific (row,col) index in an C++ Eigen sparse matrix?
This Code work for me
for (int i=0; i<matrix.rows(); ++i){
for(int j=0; i<matrix.cols(); ++j)
cout << " i,j=" << i << ","
<< j << " value="
<< matrix.coeff(i,j)
<< std::endl;
}
Try coeff
:
double value = matrix.coeff(iRow, iCol);
If you want a non-const version use coeffRef
instead. Note that when using coeffRef
if the element doesn't exist, it will be inserted.