Eigen elements manipulation without loop

2019-07-21 08:34发布

问题:

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?

回答1:

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

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


标签: c++ eigen