how can normalize the data between 0 and 1??
8 次查看(过去 30 天)
显示 更早的评论
how can normalize the data between 0 and 1??(exclude 0 and 1)
0 个评论
回答(2 个)
Walter Roberson
2017-2-23
mat2gray() would normalize to exactly 0 to exactly 1.
But what value do you want instead of 0? Should the smallest values be mapped to eps(realmin), which is about 1E-324 ?
3 个评论
Jan
2017-2-23
@ananthi: Accepting an answer means, that the problem is solved. Then most readers will not care about the thread anymore. Is the problem solved?
Jan
2017-2-23
编辑:Jan
2017-2-23
A cheap adjustment of the edges:
x = randn(100, 1);
xn = (x - min(x)) / (max(x) - min(x));
xn(xn == 0) = eps; % Or: eps(realmin)
xn(xn == 1) = 1 - eps;
Or consider the limits during the normalization: [EDITED, first version failed]
xmin = min(x);
xmax = max(x);
range = (xmax - xmin) + eps(xmax - xmin);
xn = (x - (xmin - eps(xmin))) / range;
% Or:
% xn = (x - (xmin - eps(xmax - xmin))) / range;
4 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Statistics and Machine Learning Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!