summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Franzke <benjaminfranzke@googlemail.com>2012-05-11 10:07:48 +0200
committerBenjamin Franzke <benjaminfranzke@googlemail.com>2012-05-11 10:16:45 +0200
commit241d4a8570d5f7b766c76ca20e4d2454ba4ee4c8 (patch)
tree0223dd483bf2732dad253f6480d1bd29a045e9fc
parent07ab1ba8ad47d804668ac90e50f95fb41a437c49 (diff)
downloaddmc-241d4a8570d5f7b766c76ca20e4d2454ba4ee4c8.tar.gz
dmc-241d4a8570d5f7b766c76ca20e4d2454ba4ee4c8.tar.bz2
dmc-241d4a8570d5f7b766c76ca20e4d2454ba4ee4c8.zip
normalize: Normalize max=min to 1
-rw-r--r--normalize.m6
1 files changed, 4 insertions, 2 deletions
diff --git a/normalize.m b/normalize.m
index 44f2e7b..5df13df 100644
--- a/normalize.m
+++ b/normalize.m
@@ -1,13 +1,15 @@
function n = normalize(data)
if (size(data, 1) == 1)
data = data';
+ end
_min = repmat(min(data), size(data, 1), 1);
_max = repmat(max(data), size(data, 1), 1);
equals = (_min == _max);
if any(any(equals))
- _min = _min .* ~equals;
- _max = _max .* ~equals + ones(size(_max)) .* equals;
+ _min(equals) = 0;
+ % Prevent division by zero, and devide by 1
+ _max(_max == 0) = 1;
end
n = (data - _min) ./ (_max - _min);
end