-
Notifications
You must be signed in to change notification settings - Fork 1
/
normalization.m
56 lines (52 loc) · 1.24 KB
/
normalization.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
function normal = normalization(x,kind)
% by Li Yang BNU MATH Email:[email protected] QQ:516667408
% last modified 2009.2.24
%
if nargin < 2
kind = 2;%kind = 1 or 2 表示第一类或第二类规范化
end
[m,n] = size(x);
normal = zeros(m,n);
%% normalize the data x to [0,1]
if kind == 1
for i = 1:m
if x(i,:) == zeros(1,n)
normal(i,:) = x(i,:);
else
ma = max( x(i,:) );
mi = min( x(i,:) );
normal(i,:) = ( x(i,:)-mi )./( ma-mi );
end
end
end
%% normalize the data x to [-1,1]
if kind == 2
for i = 1:m
if x(i,:) == zeros(1,n)
normal(i,:) = x(i,:);
else
mea = mean( x(i,:) );
va = var( x(i,:) );
normal(i,:) = ( x(i,:)-mea )/va;
end
end
end
%% normalize the data x to [-1,1]
if kind == 3
for i = 1:m
if x(i,:) == zeros(1,n)
normal(i,:) = x(i,:);
else
normal(i,:) = x(i,:)/norm(x(i,:));
end
end
end
if kind == 4
for i = 1:m
if x(i,:) == zeros(1,n)
normal(i,:) = x(i,:);
else
normal(i,:) = x(i,:)/max(x(i,:));
end
end
end