Info
この質問は閉じられています。 編集または回答するには再度開いてください。
how to sum a 9 matrice in a for loop ?
4 ビュー (過去 30 日間)
古いコメントを表示
i have a 9 matrice (7 8 9;2 1 4; 5 6 3) and i have to write a code in a for loop that gives me the answer to the sum of all 9 numbers
2 件のコメント
Erivelton Gualter
2019 年 11 月 19 日
Do you means, you want the sum of all the values for a given matrix (for example, (7 8 9;2 1 4; 5 6 3)) ?
回答 (1 件)
KALYAN ACHARJYA
2019 年 11 月 19 日
編集済み: KALYAN ACHARJYA
2019 年 11 月 19 日
"May the question is: how to sum a 9 matrices elements in a for loop?"
No need of loop, here mat is given matrix
result=sum(mat(:))
Must be loop have to use, then,
Hints:
for i=1:r
for j=1:col
sum_mat=sum_mat+mat(i,j);
end
end
2 件のコメント
KALYAN ACHARJYA
2019 年 11 月 19 日
Then Hints are sufficient, I will not tell you more. Please read Matlab documentation.
この質問は閉じられています。
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!