How to calculate euclidean distance between two feature vectors
41 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentario
Awais Khan
el 1 de Mzo. de 2020
i you known approch of finding eclidean distance, then please share it, i am facing same issue.
Respuestas (2)
Jos (10584)
el 16 de Feb. de 2018
Take a look at * norm*
EuclideanDistance = norm(vec2-vec1, 2)
0 comentarios
Guillaume
el 1 de Mzo. de 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 comentarios
Ver también
Categorías
Más información sobre Statistics and Machine Learning Toolbox en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!