Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Submatrices and indices using Eigen

I'm currently working on a MATLAB project and I'd like to re-implement the most computational-heavy parts using C++ and Eigen. I'd like to know if there's a way to perform the following operation (MATLAB syntax):

B = A(A < 3);

For those who are not familiar with MATLAB, the above-mentioned command initializes a matrix B made of the cells in A whose values are less than 3.

I've seen from a post on the Eigen forum that it's possible to obtain the indices of interest by using:

MatrixXi indices = (A.array() < 3).cast<int>();

What I'd like to have is something like:

MatrixXd B = A(A.array() < 3);

Thanks.

like image 933
Ilio Catallo Avatar asked Nov 24 '12 09:11

Ilio Catallo


Video Answer


1 Answers

libigl has many wrappers for Eigen to make it feel more like MATLAB. In particular, there is a slice function so that you can call:

igl::slice(A,indices,B);

which is equivalent to MATLAB's

B = A(indices)
like image 145
Alec Jacobson Avatar answered Oct 16 '22 09:10

Alec Jacobson