MATLAB: Sum of Euclidean distances

sum

Hi.
There are 5 points in 3D space: xyz=rand(5,3).
How can I quickly calculate a sum of Euclidean distances from the 1st point till the rest of points (2nd-5th)?
Thanks.

Best Answer

diffs = bsxfun(@minus, xyz(2:end,:), xyz(1,:));
distance = sum(sqrt(sum(diffs.^2, 2)))