MATLAB: Is there any way to normalize any matrix values to be between (-1) and (1)

normalizationnormalize

Hello,
Is there any way to normalize any matrix values to be exactly between (-1) and (1)? I attached the matrix.
regards,

Best Answer

You can use mat2gray(), which normalizes data from 0-1 then just scale and subtract 1 to get into the range -1 to +1:
M = 2*mat2gray(M)-1;
A nice single-line solution.