function histogramize_test ( )

%*****************************************************************************80
%
%% HISTOGRAMIZE_TEST tests HISTOGRAMIZE.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    19 July 2018
%
%  Author:
%
%    John Burkardt
%
  timestamp ( );
  fprintf ( 1, '\n' );
  fprintf ( 1, 'HISTOGRAMIZE_TEST:\n' );
  fprintf ( 1, '  MATLAB/Octave version %s:\n', version ( ) );
  fprintf ( 1, '  HISTOGRAMIZE groups data into histogram bins.\n' );

  n = 50;
  x = 5.0 + 10.0 * rand ( n, 1 );

  fprintf ( 1, '\n' );
  fprintf ( 1, '  Data:\n' );
  fprintf ( 1, '\n' );
  for i = 1 : n
    fprintf ( 1, '  %2d  %g\n', i, x(i) );
  end

  bin_min = 5.0;
  bin_max = 15.0;
  bin_num = 10;

  fprintf ( 1, '\n' );
  fprintf ( 1, '  Bin minimum = %g, maximum = %g\n', bin_min, bin_max );
  fprintf ( 1, '  Number of bins = %d\n', bin_num );

  [ bin_ave, bin_count ] = histogramize ( n, x, bin_min, bin_max, bin_num );

  fprintf ( 1, '\n' );
  fprintf ( 1, '  Binned data:\n' );
  fprintf ( 1, '  Index  Count Min Max\n' );
  fprintf ( 1, '\n' );
  for i = 1 : bin_num
    lo = bin_min + ( i - 1 ) * ( bin_max - bin_min ) / ( bin_num );
    hi = bin_min +   i       * ( bin_max - bin_min ) / ( bin_num );
    fprintf ( 1, '  %2d  %2d  %8.2g  %8.2g\n', i, bin_count(i), lo, hi );
  end
%
%  The histogrammed data can be displayed as a bar chart.
%
  bar ( bin_ave, bin_count )
  grid on
  title ( 'Histogram of random data' )
  xlabel ( 'Bin average' )
  ylabel ( 'Bin frequency' )

  pause ( 5 )
%
%  Save a copy of the plot as a PNG file.
%
  filename = 'histogramize_test.png';
  print ( '-dpng', filename );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  Graphic data saved in "%s"\n', filename );
%
%  Terminate.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'HISTOGRAMIZE_TEST:\n' );
  fprintf ( 1, '  Normal end of execution.\n' );
  fprintf ( 1, '\n' );
  timestamp ( );

  return
end

