필터 지우기
필터 지우기

Find the some of a row with numbers greater than -1 in matlab

조회 수: 3 (최근 30일)
Aurelius Hardy
Aurelius Hardy 2022년 11월 23일
댓글: Image Analyst 2022년 11월 23일
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
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.
Aurelius Hardy
Aurelius Hardy 2022년 11월 23일
Maybe I'm looking at this wrong. Row 1 includes inches of of snow received each day. Some days didn't have snow recorded so the -999 was placed there. Therefore, that sum shouldn't be included in the sum of row 1. So I want to get the sum of days that had snow >/= 0.

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2022년 11월 23일
B = [103, 61, 0, 0, 62, -999, -999, 0, 0, 2]
B = 1×10
103 61 0 0 62 -999 -999 0 0 2
sum( max(B, 0), 2)
ans = 228
  댓글 수: 3
Walter Roberson
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
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 CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by