% You can also use http://www.cad.zju.edu.cn/home/dengcai/Data/code/NormalizeFea.m.

matlab中對一個矩陣的行(列)歸一化為二范數是1的簡潔代碼:一句實現
%  normalize each row to unit
A = A./max(1e-12,repmat(sqrt(sum(A.^2,2)),1,size(A,2)));% 1e-12 is similar as %http://www.cad.zju.edu.cn/home/dengcai/Data/FaceData.html to avoid the problem that one row of A is zero
%  normalize each column to unit
A = A./max(1e-12,repmat(sqrt(sum(A.^2,1)),size(A,1),1));
% % Nannan wang says that in matlab, cycling(循環) is time-consuming.
% % 能不用循環就不用循環
% % Examples
% A=[3 4;5 12];
% [m n] = size(A);
% % normalize each row to unit
% for i = 1:m
%     A(i,:)=A(i,:)/norm(A(i,:));
% end
% A
% % another beautiful way to normalize each row to unit
% A=[3 4;5 12];
% A = A./repmat(sqrt(sum(A.^2,2)),1,size(A,2));
% A
% % normalize each column to unit
% A=[3 4;5 12];
% for i = 1:n
%     A(:,i)=A(:,i)/norm(A(:,i));
% end
% A
% % another beautiful way to normalize each column to unit
% A=[3 4;5 12];
% A = A./repmat(sqrt(sum(A.^2,1)),size(A,1),1);
% A