How to relate or understand this code with math formula?

Having a matrix (Vertices) with vertices points of a skeleton line (all points x,y). And two (column) vector matrices Na and Nb which describe the logical indexes of the matrix Vertices... can someone explain me better (the actual mathematics) of these pieces of code? Well, actually are the same:
% Correct for sampling differences
Ta = -sqrt(sum((Vertices-Vertices(Na,:)).^2,2));
Tb = sqrt(sum((Vertices-Vertices(Nb,:)).^2,2));

1 commentaire

Mauricio Escobar
Mauricio Escobar le 13 Mar 2013
Modifié(e) : Mauricio Escobar le 13 Mar 2013
So is the distance between two points: sqrt[ (x - y)^2 +(x'- y')^2 ]
I still have one doubt...
The part after squaring: ,2 ));
Inside the sum(().^2 , 2)
What does it do?
Is it to sum two columns?

Connectez-vous pour commenter.

 Réponse acceptée

Doug Hull
Doug Hull le 12 Mar 2013

0 votes

It looks like it is taking the delta between every vertex in the list and a specific vertex (a or b).
It is then squaring those two scalars, deltaX and deltaY
It is then summing them
Then taking the square root of the is. Is is negating the first one.
Essentially, it is finding the distance between a point and a list of points.

4 commentaires

Thanks Doug Hull (excellent videos on GUI BTW! Thanks for those, a lot!)
When you say delta, what do you mean? The difference, right?
Mauricio Escobar
Mauricio Escobar le 13 Mar 2013
Modifié(e) : Mauricio Escobar le 13 Mar 2013
I still have one doubt...
The part after squaring: ,2 ));
Inside the sum(().^2 , 2)
What does it do?
Is it to sum two columns?
sum along the second dimension (i.e., along the rows). sum() defaults to summing down the columns.
Thanks Walter!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Graph and Network Algorithms dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by