Borrar filtros
Borrar filtros

Proportional change of values with a fixed sum

4 visualizaciones (últimos 30 días)
Sandra Cortes
Sandra Cortes el 30 de Oct. de 2017
Comentada: Sandra Cortes el 31 de Oct. de 2017
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%.

Respuesta aceptada

Roger Stafford
Roger Stafford el 30 de Oct. de 2017
Editada: Roger Stafford el 30 de Oct. de 2017
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 comentario
Sandra Cortes
Sandra Cortes el 31 de Oct. de 2017
Oh I see. Thank you so much for your help!! I applied it by changing several values at the same time and works perfectly!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Interactive Control and Callbacks en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by