I have a function as follows:

My optimized matlab code is:
function gamma = calcGamma(H, d, delta, f)
s= size(H);
Nv = s(1);
Ne = s(2);
gamma = zeros(Ne,1);
for e =1:Ne
hue = H(:,e);
sdu=f./sqrt(d);
mHUE = repmat(hue',Nv,1);
mHVE = repmat(hue,1,Nv);
mSDU = repmat(sdu',Nv,1);
mSd = repmat(sdu,1,Nv);
ss1 = mHUE .* mHVE/delta(e) .* (mSDU-mSd).^2;
gamma(e) = sum(ss1(:));
end
However, since Ne is very big, it takes quite a long time to calculate the function.
I see an similar question with a good solution, but I do not understand how it is derived.

Any solution to avoid the for-loop? Thanks
H,d,gammaandf? And is the difference betweengammaandgamaintentional? - Bas Swinckels