could anyone tell me how to get the sum of an array to a fixed number say 12

1 view (last 30 days)
could anyone tell me how to get the sum of an array to a fixed number say 12

Accepted Answer

Torsten
Torsten on 26 Jan 2018
a = 12*a/sum(a)
if a is the array.
Best wishes
Torsten.
  2 Comments
Prabha Kumaresan
Prabha Kumaresan on 26 Jan 2018
ok.But with respect to your answer the sum of array will be fixed to 12,eventhough the answer will not be equal to 12.But what I need is the sum of the array should be 12 while adding the numbers in the array eventhough if it not 12..Could you tell me how to replace the numbers to get the sum of the array to be 12.
Torsten
Torsten on 29 Jan 2018
If you have an array "a" that does not sum to 12, replace it with "12*a/sum(a)". This array will sum to 12.
Best wishes
Torsten.

Sign in to comment.

More Answers (0)

Categories

Find more on Characters and Strings in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!