Suppose I have 2 vectors and I want to do an outer product. I could use:
A=x*y';
Or I could use bsxfun
like that:
bsxfun(@times,x,y')
But I want to batch outer products. I have 2 matrices, each holds p
vectors:
n=1000; p=6;
A=rand(n,p);
D=rand(n,p);
And I want to calculate all the outer products and sum the results like so:
AA=zeros(n,n);
for j=1:p
AA = AA + A(:,j) * D(:,j).';
end
I want to do this more efficiently but I can't figure out how.