Suppose I have a matrix of elements like so:
A = reshape(1:25, 5, 5) A = 1 6 11 16 21 2 7 12 17 22 3 8 13 18 23
This -
B = permute(bsxfun(@times,A,permute(A,[3 2 1])),[1 3 2])