Euclidean distance

 

The Euclidean distance is the true straight line distance, and the Euclidean distance between vectors A and B can be calculated using the function dis(A,B).

For example, there are 5 samples in the table, find the Euclidean distance between every two samples


X

Y

1

22

7.25

2

38

71.2833

3

26

7.925

4

35

53.1

5

35

8.05


A

B

1

[[22,7.25],[38,71.2833],[26,7.925],[35,53.1],[35,8.05]]

[]

2

for A1

=A1.(dis(A2,~))

3


>B1=B1|[B2]

A1 Input the sample data

B1 Define an empty sequence to hold the results

A2:B3 Loop A1, calculate the Euclidean distance between the two samples, and store the result in B1

After the above code is executed, B1 returns the Euclidean distance matrix between the samples

..