MATLAB: Multiply then sum elements of two matrices

additionmatricesmultiplication

What's the best way to 1) multiply all the elements between two similar sized matrices then 2) sum them into one single number/outcome?

Best Answer

It is not clear from your question whether corresponding elements are to be multiplied or if you are wanting to do a matrix multiplication.
If corresponding elements are to be multiplied, then you could calculate the sum-of-products using
dot(A(:),B(:))