function xs = r8mat_scale_ab ( m, n, x, a, b )

%*****************************************************************************80
%
%% r8mat_scale_ab() scales the columns of an R8MAT to [A,B].
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    08 October 2018
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer M, N, the number of entries in the vector.
%
%    real X(M,N), the array to be scaled.
%
%    real A, B, the new minimum and maximum.
%
%  Output:
%
%    real XS(M,N), the scaled array.
%
  [ m, n ] = size ( x );
  xmin = min ( x );
  xmax = max ( x );
  xs = zeros ( m, n );
  for j = 1 : n
    if ( 0.0 < xmax(j) - xmin(j) )
      xs(1:m,j) = a + ( b - a ) *( x(1:m,j) - xmin(j) ) / ( xmax(j) - xmin(j) );
    else
      xs(1:m,j) = ( a + b ) / 2.0;
    end
  end

  return
end

