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.
%
%  Modified:
%
%    07 May 2019
%
%  Author:
%
%    Paul Nahin
%
%  Reference:
%
%    Paul Nahin,
%    Dueling Idiots and Other Probability Puzzlers,
%    Princeton, 2012,
%    ISBN: 978-0691155005.
%
%  Parameters:
%
%    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 = zeros ( 1, stop );
  for i = 1 : stop
    data(i) = rand ( );
  end

  for i = 1 : 1000
    x(i) = data(i);
    y(i) = data(i+j);
  end
%
%  Graphics.
%
  clf
  plot ( x, y, '.' )
  xlabel('j = 9')
  title('1000-Point Scatter Diagram for MATLAB 5.2 Uniform Random Number Generator')
  filename = 'correlation.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );
  pause ( 5 );

  return
end
