Efficiently compute a 3D matrix of outer products – MATLAB

This is just a minor improvement over Divakar’s answer. It is a little faster because it replaces a 3D-array permute with a 2D-array permute:

B = bsxfun(@times, permute(A, [1 3 2]), permute(A, [3 1 2]));

Leave a Comment