Sum of Euclidean distances

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.

 採用された回答

David Young
David Young 2011 年 11 月 14 日

0 投票

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

その他の回答 (1 件)

Grzegorz Knor
Grzegorz Knor 2011 年 11 月 14 日

0 投票

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

カテゴリ

ヘルプ センター および File ExchangeNumerical Integration and Differential Equations についてさらに検索

タグ

質問済み:

2011 年 11 月 14 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by