What's wrong with
mm = bsxfun(@times,permute(m,[r,c,1]),permute(m,[c,r,1]));
Which, if you haven't recognized it, can be written as
As Guillaume astutely points out, the permute indices are NOT size(m)-dependent, but reflect the dimensionality of m as 2D array. The above, while cute, is nonsensical for the purpose.