How to calculate euclidean distance between two feature vectors

41 Ansichten (letzte 30 Tage)
Sumit Vaise
Sumit Vaise am 16 Feb. 2018
Beantwortet: Guillaume am 1 Mär. 2020
I have a vector vec1 which hold features of two images (For e.g. Img1 features in first row and second image feature in 2nd row) of size 2x2559. Similar to this other vector vec2 holding feature of same size. Now I need to find the euclidean distance between the two vectors so that i can find how similar the two images are, one from vec1 and vec2 are?
i tried:
calculating distance row wise:
Dist = sqrt(sum((vec1-vec2).^2,2));
also,
Dist = pdist2(vec1,vec2,'euclidean')
Is this the right approachto find the euclidean distance?
  1 Kommentar
Awais Khan
Awais Khan am 1 Mär. 2020
i you known approch of finding eclidean distance, then please share it, i am facing same issue.

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Jos (10584)
Jos (10584) am 16 Feb. 2018
Take a look at * norm*
EuclideanDistance = norm(vec2-vec1, 2)

Guillaume
Guillaume am 1 Mär. 2020
"Is this the right approachto find the euclidean distance?"
Depends on which euclidean distance you're trying to calculate.
Both of your expressions consider each row of vec1 and vec2 as the coordinates of a point in N-D space (N = 2559) and calculate the euclidean distance between the two points thus defined in vec1 and in vec2. The only difference between the two expressions is that your first one calculate the distance between point 1 (first row) of vec1 and point 1 (first row) of vec2, then between point 2 (2nd row) of vec1 and point 2 of vec2, resulting in a 2x1 distance, whereas your 2nd expressions calculates distance between each combination of points (1-1, 1-2, 2-1, 2-2), resulting in a 2x2 matrix (whose diagonal will be 0).
If that's what you meant to calculate then you're better off using your first expression, it'll be faster.

Kategorien

Mehr zu Statistics and Machine Learning Toolbox finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by