%% PDIST_EXAMPLE shows how PDIST can compute a table of distances.
%
%  Make a data set of 5 points in 2D.
%
  x = [ 1,  1;
        1,  2;
        2,  1;
       -1, -1;
       -1, -2 ];
%
%  Plot the points, using BLACK (K) crosses (X).
%
  plot ( x(:,1), x(:,2), 'kx' );
%
%  Make the visible area have equal height and width.
%  Assign the coordinate axes as -3 <= X <= 3, -3 <= Y <= 3.
%  Add grid lines.
%  Label each point.
%
  axis square
  axis ( [ -3, 3, -3, 3 ] );
  grid on
  text ( x(:,1)+.1, x(:,2)+.1, '1|2|3|4|5' );
%
%  Now find the Euclidean distance between points using PDIST.
%  PDIST returns a vector that represents the upper triangle of the 
%  distance table.
%  SQUAREFORM makes a nice square matrix out of that data.
%
  d = pdist ( x, 'euclid' );
  dist_euclid = squareform ( d )
%
%  'Euclid' is the default argument for PDIST, so you can say 
%   D = PDIST ( X ).
%   Another useful value is 'CITYBLOCK' which gives the L1 distance.
%   Compare the cityblock distances printed out to what you can
%   see with your eye on the plot.
%
  d = pdist ( x, 'cityblock' );
  dist_cityblock = squareform ( d )
