forked from xiaodongyang/SNV
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scaleData.m
36 lines (26 loc) · 837 Bytes
/
scaleData.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
function [featScale, matScale] = scaleData(feat, minScale, maxScale, matScale)
% initialize
[nfeats ndims] = size(feat);
featScale = zeros(nfeats,ndims);
%if matScale is not specified, build it from feat
if nargin < 4
% initialize matScale
matScale = zeros(2,ndims);
% min value at each dimension of feat
matScale(1, :) = min(feat, [], 1);
% max value at each dimension of feat
matScale(2, :) = max(feat, [], 1);
end
% each dimension to the same scale and offset.
for i = 1:ndims
col = feat(:, i);
minval = matScale(1, i);
maxval = matScale(2, i);
if (maxval - minval) ~= 0
colScale = (maxScale - minScale) / (maxval - minval) * (col - minval) + minScale;
else
colScale = zeros(length(col), 1);
end
featScale(:, i) = colScale;
end
end