I'm running the following code
a = normrnd(0,1,5000, 300);
b = normrnd(0, 1, 5000, 50);
tic
xp = repmat(a,1,1,50) .* permute(repmat(b, 1,1, 300), [1 3 2]);
toc
which outputs
Elapsed time is 0.425773 seconds.
Apparently the vast majority of execution time is spent on the repmat and permute part. I thought some alternative implementation with bsxfun might help to speed it up quite a bit, but I don't see exactly how. Is there any better way of dealing with this? Thank you!