Almost. You need the first part also:
(ones(ncentres, 1) * sum((x.^2)', 1))'
sum((x.^2)', 1) this is: square elements, transpose, sum over 1st dimension.
Then it is mutliplied with a [M x 1] matrix consisting of 1s from the right and transposed afterwards. Shorter (and faster):
sum(x.^2, 2) * ones(1, ncentres)
The multiplication repeates the columns only, so this is equivalent to:
repmat(sum(x.^2, 2), 1, ncentres)
