I have two matrices A
and B
for which I want to do a multiplication for each of their columns to produce a new matrix. The first thing cross my mind is
A = rand(4,3);
B = rand(4,3);
for J=1:SIZE(A,2)
for jj=1:size(B,2)
C(:,:,m) = A(:,j)*B(:,jj)' ;
m = m+1 ;
end
end
But I don't want to use for
loops which makes it slow. Is there any way?
I am going to use the matrices of third dimension of C
, the ones which are built by multiplication of columns of A
and B
, Is it better to first build the C
and then use its 3rd dimension matrices in each loop or just do the multiplication in each loop?