Please help me to solve the issue for the following code
1 回表示 (過去 30 日間)
古いコメントを表示
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
2018 年 1 月 26 日
If you don't get an answer to work, you should comment there, NOT open a new question.
採用された回答
Rik
2018 年 1 月 26 日
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 件のコメント
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
2018 年 1 月 29 日
2 件のコメント
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;
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!