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

1 visualizzazione (ultimi 30 giorni)
could anyone tell me how to get the sum of an array to a fixed number say 12

Risposta accettata

Torsten
Torsten il 26 Gen 2018
a = 12*a/sum(a)
if a is the array.
Best wishes
Torsten.
  2 Commenti
Prabha Kumaresan
Prabha Kumaresan il 26 Gen 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 il 29 Gen 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.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Characters and Strings in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by