While Octave has "endfor", Matlab uses "end" for FOR loops.
BSXFUN ist faster than expanding the data by REPMAT.
SUM(Matrix, 2) replies a column vector, so I'd expect problems when you assign "dist_i" to a row of the result.
The missing pre-allocation slows down this function dramatically for larger inputs.
I think, this function cannot be used in its current state. Substantial changes in the code and a more detailed help section would be a a welcome improvement.