Scaling positive and negative weights

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?

 채택된 답변

Image Analyst
Image Analyst 2013년 9월 22일

0 개 추천

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
Image Analyst 2013년 9월 22일
I hope that wasn't your homework!!! I don't want to make you a plagiarist.
dave
dave 2013년 9월 22일
편집: dave 2013년 9월 22일
Thanks, there's only the problem that one of weights will be zero. But I need all of them to be > 0. btw: Don't worry, this has nothing to do with any kind of homework..
Add a very small amount, like eps
newSignal = signal - min(signal) + eps;

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 MATLAB Coder에 대해 자세히 알아보기

태그

질문:

2013년 9월 22일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by