pdist2
Compute distances between rows of two matrices.
Syntax
d = pdist2(m1, m2)
d = pdist2(m1, m2, metric)
Inputs
- m1
- The first matrix on which to operate.
- m2
- The second matrix on which to operate, having the same number of columns as m1.
- metric
- The distance function to compute.
Outputs
- d
- The distance values. If m1 and m2 have p and q rows, respectively, then d has dimensions pxq.
Example
m1 = [1,2,3;4,6,8;5,10,15;16,26,36];
m2 = [2,4,6;3,6,9;4,8,12];
p = pdist2(m1, m2)
p = [Matrix] 4 x 3
3.74166 7.48331 11.22497
3.46410 1.41421 4.47214
11.22497 7.48331 3.74166
39.74921 36.02777 32.31099
Comments
Element d(i,j) is computed from m1(i,:) and m2(:,j).