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 t
You can perform operations on selected elements only with select()
, which is the equivalent for the ternary ?: operator. This is not exactly what you wanted, but should work in many cases.
MatrixXd B = (A.array() < 3).select(operation_on(A), MatrixXd::Zero(A.rows(), A.cols()));
This will fill B with zeros if A<3 and the result of any required operation on A otherwise.