# Mat.forEach for 2 Matrices? Compare elements

Hey there,

i successful implemented Mat.forEach for efficient computing values of one Matrix. However for my next step i need to compare each value of 2 matrixes and compute the difference in percent. The most efficient way to iterate over each element of a Matrix is using forEach. Is there a possible way to compare each elements of 2 matrixes using forEach?

please be more concise. what's the purpose of it ?

you should avoid iterating at all cost, and prefer builtin vectorized functions like compare() instead.

again this is somewhat an XY problem. the solution Y you ask about is most likely not the correct answer to problem X, but we need to know the problem to answer.

which language are you talking about, even ?

thanks for your reply.

I need to compute the difference of brightness of each frame in percent. My brightness is a 1 Channel Mat. I use c++ because i need real time observation.

I know that iterating should be avoided. Because of that i want to use .forEach Method for maximum speed because it also uses multithreading. However i dont see how i can implement the per value comparison of 2 Mat with .forEach

absdiff() and sum()

in percent of what ?

in percent to the first recorded frame