Sum of Euclidean distances
2 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
David Young
2011-11-14
diffs = bsxfun(@minus, xyz(2:end,:), xyz(1,:));
distance = sum(sqrt(sum(diffs.^2, 2)))
0 个评论
更多回答(1 个)
Grzegorz Knor
2011-11-14
sum((xyz(2:end,:)-repmat(xyz(1,:),size(xyz,1)-1,1)).^2,2).^0.5
or with loop;
for k=2:5
d(k-1) = norm(xyz(1,:)-xyz(k,:));
end
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Statistics and Machine Learning Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!