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

조회 수: 2 (최근 30일)
could anyone tell me how to get the sum of an array to a fixed number say 12

채택된 답변

Torsten
Torsten 2018년 1월 26일
a = 12*a/sum(a)
if a is the array.
Best wishes
Torsten.
  댓글 수: 2
Prabha Kumaresan
Prabha Kumaresan 2018년 1월 26일
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 2018년 1월 29일
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.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by