I don't see your rho and sigma variables, but you could try
sumexpr = optimexpr;
for i = 1:n
for j = 1:n
sumexpr = sumexpr + w(i)*w(j)*rho(i,j)*sigma(i)*sigma(j);
It would undoubtedly be more efficient to write this double summation as a standard MATLAB matrix multiplication, something like
where M has an appripriate definition, but the double sum should work, too.
MATLAB mathematical toolbox documentation