Find the some of a row with numbers greater than -1 in matlab
1 次查看(过去 30 天)
显示 更早的评论
Numbers in row 1 are: 103, 61, 0, 0, 62, -999, -999, 0, 0, 2
I'm using sum(B,2)
but how can I sum all rows greater than or equal to 0
2 个评论
DGM
2022-11-23
Explain what it means to "sum all rows greater than or equal to 0"
and what that has to do with numbers greater than -1
and what that has to do with the values in row 1.
采纳的回答
Walter Roberson
2022-11-23
B = [103, 61, 0, 0, 62, -999, -999, 0, 0, 2]
sum( max(B, 0), 2)
3 个评论
Walter Roberson
2022-11-23
Note that sum(B(B>0)) would only work for a single row, whereas the max solution works for multiple rows
Image Analyst
2022-11-23
@Aurelius Hardy please click the "Accept this answer link" to award @Walter Roberson reputation points and let others know it's already been solved. Thanks in advance 🙂.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!