필터 지우기
필터 지우기

Proportional change of values with a fixed sum

조회 수: 1 (최근 30일)
Sandra Cortes
Sandra Cortes 2017년 10월 30일
댓글: Sandra Cortes 2017년 10월 31일
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%.

채택된 답변

Roger Stafford
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.)
  댓글 수: 1
Sandra Cortes
Sandra Cortes 2017년 10월 31일
Oh I see. Thank you so much for your help!! I applied it by changing several values at the same time and works perfectly!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by