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

1 visualización (últimos 30 días)
could anyone tell me how to get the sum of an array to a fixed number say 12

Respuesta aceptada

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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Characters and Strings en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by