Take the denominator for instance. Literally written out, this would be
denominator = 0;
denominator = denominator + B(k,j)^2;
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.