MATLAB: Hi, please I want to calculate the distance between this tow matrix using pdist2 MATLABmatrixpdist2 Best Answer Olfa p=[26 255 255 255 0 255 255] s=[255 255 255 255 0 255 255] % vector distance from p to s s-p = 229 0 0 0 0 0 0the euclidean distance is the magnitude or norm of the vector distance s_p_dist_euclid=pdist2(s,p,'euclidean') = 229the square euclidean distance is the area of the square with side the previous euclidean distances_p_dist_sqeuclid=pdist2(s,p,'squaredeuclidean') = 52441229*229 = 52441citiblock distance s_p_dist_cityblock=pdist2(s,p,'cityblock') s_p_dist_cityblock = 229minkowski default coeff is 2>> s_p_dist_mink=pdist2(s,p,'minkowski')s_p_dist_mink = 229 s_p_dist_mink=pdist2(s,p,'minkowski',1.5) s_p_dist_mink = 2.289999999999999e+02Cheby distance: maximum coordinate difference s_p_dist_chevy=pdist2(s,p,'chebychev') s_p_dist_chevy = 229cosine distance: 1-cos(alpha) alpha is the angle between vectors s and p s_p_dist_cos=pdist2(s,p,'cosine') s_p_dist_cos = 0.069480529510180correlation distance: 1-sample correlation, it means, the opposite of the correlation s_p_dist_corr=pdist2(s,p,'correlation') s_p_dist_corr = 0.307354858007336the correlation distance of of same vectors would be null because it's max correlateds_p_dist_corr=pdist2(p,p,'correlation') = 2.220446049250313e-16hamming distance: the percentage of coordinates that differs_p_dist_hamming=pdist2(s,p,'hamming') = 0.142857142857143only one coordinate different: 1/7 = 0.142857142857143Jaccard distance: percentage of nonzero coordinates that differs_p_dist_jaccard=pdist2(s,p,'jaccard') = 0.166666666666667you also define a custom distance functionD = pdist2(X,Y,@distfun)the custom distance function has to have this headerfunction D2 = distfun(ZI, ZJ)If you find this answer of any help solving your question, please click on the thumbs-up vote link, or mark it as accepted answerthanks in advanceJohnjgb2012@sky.com Related SolutionsMATLAB: How to calculate the shortest distance between points and a line You can use the point_to_line_distance function. MATLAB: Compute distances between an element and all other elements of a matrix If you have the statistics toolbox you can use pdist2m=[1 1 1 1;2 2 2 2;3 3 3 3;4 4 4 4;5 5 5 5]dist1=pdist2(m(1,:),m,'euclidean')dist2=pdist2(m(1,:),m,'cityblock')%plot index vs distanceplot(1:length(c),[dist1;dist2]) Related QuestionHow to calculate total hamming distanceHow to calculate distance from one point base to multipoints and save it as a row
Best Answer