Please help me to solve the issue for the following code

조회 수: 1 (최근 30일)
Prabha Kumaresan
Prabha Kumaresan 2018년 1월 26일
댓글: Prabha Kumaresan 2018년 1월 29일
I have asked this question already but I couldnt get the answers what i actually need.
A=[0.01 0.02 0.03 0 0 0 0.02;
0.02 0.03 0.04 0 0 0 0.03;
0.03 0.02 0.02 0 0 0 0.04]
s=sum(sum(A))
if i run the code it gives the value 0.3100.
But how to replace the numbers such that the sum of A should be 0.35. could anyone help me on this
  댓글 수: 1
Rik
Rik 2018년 1월 26일
If you don't get an answer to work, you should comment there, NOT open a new question.

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

채택된 답변

Rik
Rik 2018년 1월 26일
You have a working answer here, you just didn't run the code correctly.
A=[0.01 0.02 0.03 0 0 0 0.02;
0.02 0.03 0.04 0 0 0 0.03;
0.03 0.02 0.02 0 0 0 0.04];
A = 0.35*A/sum(A(:))
s=sum(A(:))
  댓글 수: 2
Prabha Kumaresan
Prabha Kumaresan 2018년 1월 29일
편집: Walter Roberson 2018년 1월 29일
the command line A = 0.35*A/sum(A(:)) should not be included. On omitting the line s=0.31.
Could you please tell me how to change or replace the numbers in A such that the value of s=0.35.
Walter Roberson
Walter Roberson 2018년 1월 29일
Why should that line not be included? If it gets you the answer you want, then why not use it?
If you want to generate A so that it already has the right sum, then use Roger's randfixedsum() from the File Exchange.

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

추가 답변 (1개)

Prabha Kumaresan
Prabha Kumaresan 2018년 1월 29일
if i use the command line it gives the result what i need but the addition of the numbers of the matrix was not changed.
  댓글 수: 2
Walter Roberson
Walter Roberson 2018년 1월 29일
편집: Walter Roberson 2018년 1월 29일
I do not understand that remark.
Perhaps you need
new_A = 0.35*A./sum(A(:));
additions_to_A = new_A - A;
and now the additions of numbers to A that you need to reach the desired total is in the matrix additions_to_A, and you can get the desired matrix by using
desired_matrix = A + additions_to_A;
Prabha Kumaresan
Prabha Kumaresan 2018년 1월 29일
Thanks a lot.It works.

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

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by