Search code examples
c++eigen

Eigen elements manipulation without loop


I want to check if the elements of my matrix are smaller than zero then I want to assign zero to them, in matlab it was done using this:

ind = find(floatFrame < 0);
floatFrame(ind) = 0;

Is there any equivalent for Eigen matrices?


Solution

  • You can use the select function, which is similar to the ternary ?: operator in C. For your example:

    floatFrame = (floatFrame < 0).select(0, floatFrame)