Is there any way to normalize any matrix values to be between (-1) and (1)?
2 次查看(过去 30 天)
显示 更早的评论
Hello,
Is there any way to normalize any matrix values to be exactly between (-1) and (1)? I attached the matrix.
regards,
0 个评论
采纳的回答
Image Analyst
2019-1-12
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.
4 个评论
Walter Roberson
2019-1-13
They would display as -1.0000 and 1.0000 especially with short format in effect, but if you take 1-max(M(:)) and min(M(:))+1 then you will see non-zero residues.
更多回答(2 个)
madhan ravi
2019-1-12
编辑:madhan ravi
2019-1-12
a=-1;
b=1;
N=100; % number of points
A=(b-a).*rand(N,1)+a; % creates numbers inbetween -1 and 1
Steven Lord
2019-1-12
Use the normalize function with the 'range' method if you're using release R2018a or later.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!