a 2D version
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

15 lines
411 B

3 years ago
function normx = normalize(x,a,b,min0,max0)
normx = zeros(size(x));
xmax = max(x(:));
xmin = min(x(:));
if nargin > 3
% norm x with same ration of [min0, max0] -> [a,b]
a1 = a*xmin/min0;
b1 = b*xmax/max0;
k = (b1-a1)/(xmax-xmin);
normx(:) = a1 + k*(x(:)-xmin);
else
k = (b-a)/(xmax-xmin);
normx(:) = a + k*(x(:)-xmin);
end
end