How to calculate euclidean distance between two feature vectors
조회 수: 35 (최근 30일)
이전 댓글 표시
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
Awais Khan
2020년 3월 1일
i you known approch of finding eclidean distance, then please share it, i am facing same issue.
답변 (2개)
Guillaume
2020년 3월 1일
"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
참고 항목
카테고리
Help Center 및 File Exchange에서 Statistics and Machine Learning Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!