MATLAB: 2D summation loop

loopsummation

How do I create this in MATLAB?
formula.png

Best Answer

Take the denominator for instance. Literally written out, this would be
denominator = 0;
for k=1:K
denominator = denominator + B(k,j)^2;
end
Or, assuming the first dimension of B is K, then you could use the sum( ) function:
denominator = sum(B(:,j).^2);
You can construct similar code for the numerator.
Probably best if you code everything up using for-loops just to get something running that works. Then you can simplify things with the sum( ) and diff( ) functions. It is possible to do the entire operation to construct ds without loops.