How to normalize / denormalize a vector to range [-1;1]

后端 未结 4 1589
醉话见心
醉话见心 2020-11-29 05:39

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

4条回答
  •  一整个雨季
    2020-11-29 06:01

    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);
    

提交回复
热议问题