function B=srescale(A,range,mean)
%SESCALE Rescales a matrix symmetrically round a value.
%
%B=srescale(A[,range[,mean]])
%B(i,j) will become A(i,j)/max(abs(A))*range+mean. 
%range,mean defaults to 0.5,0.5.

% v1.0  94-09-16. Niclas Borlin, niclas@cs.umu.se.
% v1.1  95-07-06. Renamed from symmrescale. Default values changed to produce
%                 a mapping into [0,1].
% v1.2  95-11-22. Corrected 'all values equal' bug.

if (nargin<2)
	range=0.5;
end

if (nargin<3)
	mean=0.5;
end

mx=max([max(max(abs(real(A)))) max(max(abs(imag(A))))]);

if (mx==0)
	B=mean*ones(size(A));
else
	B=A/mx*range+mean;
end
