归一化到任意区间,并反归一化,这个很常用。写了个简单的函数,留着平时备用。
%matlab code
%normalization
function normalized = normalize(A,minOut,maxOut)
%input:
% A: the matrix to be normalize
% minOut: the minimum value after normalized
% maxOut: the maximum value after normalized
%output:
%normalized:the normalized matrix
minA=min(min(A));maxA=max(max(A));
normalized=(A-minA)/(maxA-minA)*(maxOut-minOut)+minOut;
end %end function
调用:
%normalize test
load A;
%记住A的最大值和最小值,以便反归一化时用
minA=min(min(A));maxA=max(max(B));
%归一化A到B
B=normalize(A,0,255);
%反归一化B到A
inverse_B=normalize(B,minA,maxA);
%此时inverse_B应等于A。