From 241d4a8570d5f7b766c76ca20e4d2454ba4ee4c8 Mon Sep 17 00:00:00 2001 From: Benjamin Franzke Date: Fri, 11 May 2012 10:07:48 +0200 Subject: normalize: Normalize max=min to 1 --- normalize.m | 6 ++++-- 1 file 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 -- cgit