I have a problem that I hope can be easily resolved. A is the NG matrix, B is the NG matrix. The goal is to get the matrix C

which is equal to multiplying each transposed column A by each row of B and summing the resulting matrices; the total number of such matrices before summation is NN, their size is GG. This can easily be done in MatLab with two circuits:
N=5; G=10; A=rand(N,G); B=rand(N,G); C=zeros(G); for n=1:1:N for m=1:1:N C=C+A(m,:)'*B(n,:); end end
However, for large matrices, it is rather slow.
So my question is: is there a more efficient way to calculate the matrix C in Matlab?
thanks
source share