Effacer les filtres
Effacer les filtres

Sum of Euclidean distances

3 vues (au cours des 30 derniers jours)
Lulu
Lulu le 14 Nov 2011
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.

Réponse acceptée

David Young
David Young le 14 Nov 2011
diffs = bsxfun(@minus, xyz(2:end,:), xyz(1,:));
distance = sum(sqrt(sum(diffs.^2, 2)))

Plus de réponses (1)

Grzegorz Knor
Grzegorz Knor le 14 Nov 2011
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

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by