Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

how to sum a 9 matrice in a for loop ?

조회 수: 4 (최근 30일)
Nina Nina
Nina Nina 2019년 11월 19일
마감: MATLAB Answer Bot 2021년 8월 20일
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
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)) ?
Nina Nina
Nina Nina 2019년 11월 19일
yes, i need a code written in a for loop that when you give it a 9 matrice it gives you the sum of all numbers for example you give it the matrice above and it gives you 45 (the sum of those numbers)

답변 (1개)

KALYAN ACHARJYA
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
Nina Nina
Nina Nina 2019년 11월 19일
its a school assignment where i must use a for loop
KALYAN ACHARJYA
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!

Translated by