MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

### Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

# euclidean distance of two vectors,

Asked by bala k on 9 Mar 2011

Euclidean distance of two vector. I have the two image values G=[1x72] and G1 = [1x72]. I need to calculate the two image distance value.

## Products

No products are associated with this question.

Answer by Jan Simon on 9 Mar 2011

Do you know the definition of the Euclidean distance?

```G  = rand(1, 72);
G2 = rand(1, 72);
D  = sqrt(sum((G - G2) .^ 2));
```

A more efficient method, but this matters only for much larger vectors:

```V = G - G2;
D = sqrt(V * V');
```

Or a Matlab command:

```D = norm(G - G2);
```

A good ide is to search in the documentation before asking in MATLAB Answers:

```docsearch euclidean
```

Joel on 13 Mar 2013

Do you currently have this project with you? I want to compare two vector which totals 27 feature vectors for each image.