I have two n-by-m matrices, A and B. I want to create a new matrix C which is something like:
for i = 1:n
C = C + outerProduct(A(i,:), B(i,:));
end
i.e. C is a matrix of size m x m, the sum of all outer products of the rows of A and B.
Is there a fast way to do it without a for loop (given that for loops are notoriously slow in Matlab)?
The operation you are performing (the sum of the row outer products) is equivalent to the multiplication of a transposed version of
AwithB:You can see this using the following example: