MATLAB: Could anyone help me to calculate the euclidean distance for the matrix.

euclidean distance

A= [1.8667 0.1553;
-0.0844 2.4322;
-0.3485 1.4434;
2.3628 0.6821]
I want to calculate the euclidean distance of first row with respect to second,third and fourth row.
Similarly i want to calculate the euclidean distance of second row with respect to first,third and fourth row and so on.
could anyone please help me onthis.

Best Answer

>> B = sqrt(sum(bsxfun(@minus,permute(A,[1,3,2]),permute(A,[3,1,2])).^2,3))
B =
0.00000 2.99851 2.56248 0.72363
2.99851 0.00000 1.02346 3.00859
2.56248 1.02346 0.00000 2.81615
0.72363 3.00859 2.81615 0.00000
Or use pdist (requires the Statistics Toolbox):