Assuming A
, B
and C
are MatrixXd
you can do:
C = (A.array()>B.Array()).cast<double>() * 5.0;
Question
Let's say I have two eigen matrices A and B, and I want to create a third matrix defined by
C(i,j) = 5.0 if A(i,j) > B(i,j), 0 otherwise
I guess it is possible to do it without an explicit for loop. But I am not very proficient with Eigen yet. What whould be the best approach?
Solution
Assuming A
, B
and C
are MatrixXd
you can do:
C = (A.array()>B.Array()).cast<double>() * 5.0;