function correlation ( j  )

%*****************************************************************************80
%
%% correlation() plots the scatter diagram of (X(I), X(I+J)).
%
%  Discussion:
%
%    Plotting X(I) versus X(I+J) can exhibit patterns if there is
%    correlation in the data.  If not, the scatter plot will be patternless.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    07 May 2019
%
%  Author:
%
%    Paul Nahin
%
%  Reference:
%
%    Paul Nahin,
%    Dueling Idiots and Other Probability Puzzlers,
%    Princeton, 2012,
%    ISBN: 978-0691155005.
%
%  Input:
%
%    integer J, the offset to use in the correlation.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'correlation():\n' );
  fprintf ( 1, '  Plotting X(I) versus X(I+J) can exhibit patterns if there is\n' );
  fprintf ( 1, '  correlation in the data.  If not, the scatter plot will be patternless.\n' );

  stop = 1000 + j;
  data = rand ( 1, stop );

  x(1:1000) = data(1:1000);
  y(1:1000) = data(1+j:1000+j);
%
%  Graphics.
%
  clf ( );
  plot ( x, y, '.' );
  xlabel ( 'j = 9' );
  title ( '1000-Point Scatter Diagram' )
  filename = 'correlation.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );

  return
end
