The sum of positive elements of a matrix

조회 수: 20 (최근 30일)
merowing3
merowing3 2018년 9월 18일
댓글: Christopher Wallace 2021년 1월 14일
Let M be a matrix with dimensions mxn. Calculate the sum of all positive elements of matrix M without using loop.
My code:
sum(M>0) % sum of all positive elements in respective column, we get vector with sum for each column
sum(sum(M>0)) % sum of all sums from vector
Correct or not?

채택된 답변

Christopher Wallace
Christopher Wallace 2018년 9월 18일
sum(sum(M(M > 0)))

추가 답변 (1개)

Mohamed Hossam
Mohamed Hossam 2021년 1월 14일
is there a certain command that gets the sum of postive even numbers of an array?

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by