Chances are this is a very stupid question but I spent a pretty absurd amount of time looking for it on the documentation, to no avail.
in MATLAB, the find() function gi
Not sure if this is part of your question, but to construct the appropriate element-wise inequality result you must first cast your matrices to arrays:
MatrixXd A,B;
...
Matrix C = A.array()
Now C
is the same size as A
and B
and C(i,j) = A(i,j) < B(i,j).
To find all of the indices (assuming column-major order) of the true entries, you can use this compact c++11 routine---as described by libigl's conversion table:
VectorXi I = VectorXi::LinSpaced(C.size(),0,C.size()-1);
I.conservativeResize(std::stable_partition(
I.data(), I.data()+I.size(), [&C](int i){return C(i);})-I.data());
Now I
is C.nonZeros()
long and contains indices of the true entries in C
. These two lines essentially implement find
.