% normalize(data,lvalue) normalizes each row of the data matrix so
% that it's lvalue-norm is 1.  If there is only one arg, lvalue=2.

function data=normalize(data,lvalue)

if nargin < 2
	lvalue=2;
end

[m,n]=size(data);

% normalize each row, but do it by taking the transpose and
% normalizing the columns for speed.  

data=data';
for i=1:m,
	nrm=norm(data(:,i),lvalue);
	if nrm~=0
		data(:,i)=data(:,i)/nrm;
	else
		data(:,i)=data(:,i);
	end
end
data=data';