function [newdata, low, scale] = datatool_scale(data, low, scale)
% Linearly scales the variables so that in newdata they are in the range 
% [-1,1]. Such a normalization is beneficial for the MLP.
%
% The same transform can be redone for another data by storing low and
% scale, and adding them to the call.

up    = max(data,[],2);

if nargin<3                       % If low&scale not given, compute new.
  low   = min(data,[],2);
  scale = 2 ./ (up-low);
end

newdata = -1 + diag(scale)*(-repmat(low,1,size(data,2)) + data);
