I have been googling for a while now, but cant find the answer to this simple question.
In matlab i can do this:
rows = [1 3 5 9];
A = rand(10);
B = A(rows, : );
How do i do this in eigen? It does not seem like it is possible. The closest thing i have found is
MatrixXd a(10,10);
a.row(1);
,but I want to get multiple rows/cols. Another user has also asked the question here: How to extract a subvector (of a Eigen::Vector) from a vector of indices in Eigen? , but I think there must some built in way of doing this because it is a really common operation I think.
Thanks.
While this was not possible at the time this question was asked, it has since been added in the development branch!
It's very straight forward:
Eigen::MatrixXf matrix;
Eigen::VectorXi columns;
Eigen::MatrixXf extracted_cols = matrix(Eigen::all, columns);
So I'm guessing this will be in the 3.3.5 3.4 stable release. Until then the development branch is the way to go.
Unfortunately, this is still not directly supported even in Eigen 3.3. There has been this feature request for a while: http://eigen.tuxfamily.org/bz/show_bug.cgi?id=329
Gael linked to an example implementation in one of the comments there: http://eigen.tuxfamily.org/dox-devel/TopicCustomizing_NullaryExpr.html#title1
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