Euclidean Distance

by

 

The Euclidean distance between points p and q is the length of the line segment connecting them.

Euclidean_Distance.m
%-----------------------------------------------------------------------
%   Description: Euclidean Distance Example in MATLAB 
%   Author.....: Daniel Bromand <bromand@gmail.com>
%   Date.......: 2013, May
%-----------------------------------------------------------------------

SIZE = 10;

P=     [0,0,0,0,0,0,0,0,0,0;
         0,0,0,0,1,1,0,0,0,0;
         0,0,0,1,1,1,1,0,0,0;
         0,0,0,1,1,1,1,0,0,0;
         0,0,0,0,1,1,0,0,0,0;
         0,0,0,0,1,1,0,0,0,0;
         0,0,0,1,1,1,1,0,0,0;
         0,0,0,1,1,1,1,0,0,0;
         0,0,0,0,1,1,0,0,0,0;
         0,0,0,0,0,0,0,0,0,0];
P_1D = reshape(P,1,[]);
Q = [0,0,0,0,0,0,0,0,0,0;
         0,0,0,0,1,1,0,0,0,0;
         0,0,0,1,1,1,0,0,0,0;
         0,0,0,1,1,1,0,0,0,0;
         0,0,0,0,1,1,0,0,0,0;
         0,0,0,0,1,1,0,0,0,0;
         0,0,0,1,1,1,0,0,0,0;
         0,0,0,1,1,1,1,0,0,0;
         0,0,0,0,1,1,0,0,0,0;
         0,0,0,0,0,0,0,0,0,0];
Q_1D = reshape(Q,1,[]);

ED = sqrt(sum((P_1D - Q_1D) .^ 2))

Contact us