The sum of positive elements of a matrix

21 visualizaciones (últimos 30 días)
merowing3
merowing3 el 18 de Sept. de 2018
Comentada: Christopher Wallace el 14 de En. de 2021
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?

Respuesta aceptada

Christopher Wallace
Christopher Wallace el 18 de Sept. de 2018
sum(sum(M(M > 0)))

Más respuestas (1)

Mohamed Hossam
Mohamed Hossam el 14 de En. de 2021
is there a certain command that gets the sum of postive even numbers of an array?

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by