How to calculate euclidean distance between two feature vectors
41 views (last 30 days)
Show older comments
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 Comment
Awais Khan
on 1 Mar 2020
i you known approch of finding eclidean distance, then please share it, i am facing same issue.
Answers (2)
Guillaume
on 1 Mar 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.
0 Comments
See Also
Categories
Find more on Statistics and Machine Learning Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!