Scaling positive and negative weights
6 ビュー (過去 30 日間)
古いコメントを表示
Hi, I have a vector that contains positive as well as negative weights. For example:
0.75
-0.14
-0.92
0.56
-0.28
...
Now I need a way to transform these weights so that...
- all weights will be positive.
- each weight will be greater than 0 and smaller than 1.
- the weights sum to 1.
- the more negative the original weight, the lower its new value should be.
How would I do that?
0 件のコメント
採用された回答
Image Analyst
2013 年 9 月 22 日
Just scale linearly - at least that's one of an unlimited number of ways:
% Declare random sample data.
signal = 20*rand(1,10)-10
% Offset so that the min of the new signal is at zero.
newSignal = signal - min(signal);
% Make the new signal sum to 1
newSignal = newSignal / sum(newSignal)
% Print out the sum, just to check.
fprintf('The sum is %f.\n', sum(newSignal));
3 件のコメント
Image Analyst
2013 年 9 月 22 日
Add a very small amount, like eps
newSignal = signal - min(signal) + eps;
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Spectral Measurements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!