Proportional change of values with a fixed sum
4 次查看(过去 30 天)
显示 更早的评论
Hi!
I´m new using Matlab want to know how to express in the software the change of percentages when I modify one of the values and I have a fixed sum (100%).
Say for example that I have: a= 50%, b=25%, c=25% and the sum is 100%. If I remove a, then values b and c will change into 50% to get the sum of 100%.
0 个评论
采纳的回答
Roger Stafford
2017-10-30
编辑:Roger Stafford
2017-10-30
To put your problem in general terms, suppose you have a row vector of values, v, with some given sum. For the i-th element you wish to change from v(i) = vi1 to v(i) = vi2 and adjust the remaining elements proportionally so as to retain the same overall sum. Then do this:
s = sum(v);
f = (s-vi2)/(s-vi1);
v = [f*v(1:i-1),vi2,f*v(i+1:end)];
Then v should have the same sum as before (except for possible tiny rounding error differences.) (We assume that the sum is different from vi1.)
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Interactive Control and Callbacks 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!