function a = mat2gray(x,limits)
%MAT2GRAY Convert matrix to (gray) intensity image.
%	I = MAT2GRAY(A,[amin amax]) converts the matrix A to the
%	intensity image I.  The returned matrix I contains values in 
%	the range 0 (black) to 1 (full intensity or white).
%	The limits [amin amax] are used to map the range of values
%	in Z to the range 0 to 1.
%
%	I = MAT2GRAY(A) uses the values in A to define [amin amax].
%	This is similar to using CAXIS('auto') with PCOLOR.
%
%	See also GRAY2IND.

%	Clay M. Thompson 10-5-92
%	Copyright (c) 1993 by The MathWorks, Inc.
%	$Revision: 1.10 $  $Date: 1993/09/09 19:53:16 $

if nargin==1,
  limits = [min(min(x)) max(max(x))];
end

a = max(0,min((x-limits(1))/(limits(2)-limits(1)),1));
