How can I normalize a vector to the range [-1;1]
I would like to use function norm
, because it will be faster.
Also let me
An up-to-date answer would be to use the rescale function introduced in Matlab R2017b. To normalise the vector A
to the range -1:1
, you'd run:
A = rescale(A, -1, 1);
You could undo this by saving the minimum and maximum beforehand then running rescale again:
maxA = max(A(:));
minA = min(A(:));
A = rescale(A, -1, 1);
% use the normalised A
A = rescale(A, minA, maxA);