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!