Euclidean distance between two vectors (single row matrix)

后端 未结 3 2040
一向
一向 2021-02-05 17:01

I have two vectors (single row matrices). Assume that we already know the length len.

A = [ x1 x2 x3 x4 x5 .... ]
B = [ y1 y2 y3 y4 y5 .... ]


        
相关标签:
3条回答
  • 2021-02-05 17:39

    To add to @kol answer,

    diff = A - B;
    distance = sqrt(sum(diff * diff')) % sum of squared diff
    

    or

    distance = norm(A-B);
    
    0 讨论(0)
  • 2021-02-05 17:46
    diff = A - B;
    distance = sqrt(diff * diff');
    

    or

    distance = norm(A - B);
    
    0 讨论(0)
  • 2021-02-05 18:05
    [val idx]    =  sort(sum(abs(Ti-Qi)./(1+Ti+Qi)));   
    

    or

    [val idx]    =  sort(sqrt(sum((Ti-Qi).^2))); 
    

    Val is the value and idx is the original index value of the column being sorted after applying Euclidean distance. (Matlab Code)

    0 讨论(0)
提交回复
热议问题