function correlation_heat_map ( )

%*****************************************************************************80
%
%% correlation_heat_map() draws a heat map of a correlation matrix.
%
%  Discussion:
%
%    The matrix C is symmetric, with values between -1 (highest anticorrelation)
%    and +1 (highest correlation), with 1's on the diagonal.
%
%    In this example, all the entries are positive.
%
%    The use of imshow() and colormaps in Octave is surprisingly differen
%    from what is done in MATLAB!
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    18 April 2025
%
%  Author:
%
%    John Burkardt
%
  timestamp ( );

  fprintf ( 1, '' );
  fprintf ( 1, 'correlation_heat_map():\n' );
  fprintf ( 1, '  MATLAB/Octave version: %s\n', version ( ) );
  fprintf ( 1, '  Make a heat map from a correlation matrix C(1:n,1:n)\n' );
%
%  Set the data.
%
  C = [ ...
    1.00, 0.85, 0.81, 0.86, 0.47, 0.40, 0.30, 0.38 ; ...
    0.85, 1.00, 0.88, 0.83, 0.38, 0.33, 0.28, 0.41 ; ...
    0.81, 0.88, 1.00, 0.80, 0.38, 0.32, 0.24, 0.34 ; ...
    0.86, 0.83, 0.80, 1.00, 0.44, 0.33, 0.33, 0.36 ; ...
    0.47, 0.38, 0.38, 0.44, 1.00, 0.76, 0.73, 0.63 ; ...
    0.40, 0.33, 0.32, 0.33, 0.76, 1.00, 0.58, 0.58 ; ...
    0.30, 0.28, 0.24, 0.33, 0.73, 0.58, 1.00, 0.54 ; ...
    0.38, 0.41, 0.34, 0.36, 0.63, 0.58, 0.54, 1.00 ];
%
%  Use k=16 distinct colors.
%  C is originally between 0 and 1, so multiply it by k, 
%  so that imshow will interpret C values as color indices.
%
  k = 16;
  cm = colormap ( jet(k) );
  imshow ( k * C, cm );
  colorbar ( );
  title ( 'Heat map of a correlation matrix' );
  filename = 'correlation_heat_map.png';
  print ( '-dpng', filename );
  fprintf ( 1, '' );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );
%
%  Terminate.
%
  fprintf ( 1, '' );
  fprintf ( 1, 'correlation_heat_map():' );
  fprintf ( 1, '  Normal end of execution.' );
  timestamp ( );

  return
end
function timestamp ( )

%*****************************************************************************80
%
%% timestamp() prints the YMDHMS date as a timestamp.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    14 November 2022
%
%  Author:
%
%    John Burkardt
%
  t = now ( );
  c = datevec ( t );
  s = datestr ( c, 0 );
  fprintf ( 1, '%s\n', s );

  return
end

