The sum of positive elements of a matrix

13 次查看(过去 30 天)
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
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 中查找有关 Logical 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by