I am trying to traverse Eigen::MatrixXd matrix
. However, there does not seem to be a function that returns the columns size nor the row size. Does anybody have an idea on how to do this?
The default in Eigen is column-major. Naturally, most of the development and testing of the Eigen library is thus done with column-major matrices. This means that, even though we aim to support column-major and row-major storage orders transparently, the Eigen library may well work best with column-major matrices.
The next line of the main function introduces a new type: VectorXd . This represents a (column) vector of arbitrary size. Here, the vector v is created to contain 3 coefficients which are left uninitialized.
Resizing. The current size of a matrix can be retrieved by rows(), cols() and size(). These methods return the number of rows, the number of columns and the number of coefficients, respectively. Resizing a dynamic-size matrix is done by the resize() method.
This should work...
#include <Eigen/Dense>
int main()
{
Eigen::MatrixXd matrix(3, 4);
int r = matrix.rows();
int c = matrix.cols();
for (int i = 0; i < r; ++i)
{
for (int j = 0; j < c; ++j)
{
std::cout << matrix(i,j);
}
}
return 0;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With