## I need a code to count how many raw in my matrix above zero?

### Abdullah Alsuhaymi (view profile)

on 17 Nov 2019 at 3:53
Latest activity Commented on by Abdullah Alsuhaymi

### Abdullah Alsuhaymi (view profile)

on 17 Nov 2019 at 19:34

### Image Analyst (view profile)

I have matrix and I need a code to count how many row contain negative integer
B =
1 -1
2 -2
3 3

### Image Analyst (view profile)

on 17 Nov 2019 at 17:56

Try using sum() and any():
B =[
1 -1
2 -2
3 3]
numberOfNegativeRows = sum(any(B < 0, 2))

#### 1 Comment

Abdullah Alsuhaymi

### Abdullah Alsuhaymi (view profile)

on 17 Nov 2019 at 19:34
Thank you so much it works

### Erivelton Gualter (view profile)

on 17 Nov 2019 at 3:57

You might use the function find (https://www.mathworks.com/help/matlab/ref/find.html).
Check the following code:
B = [1,-1; 2,-2; 3,3];
length(find(B<0))

Image Analyst

### Image Analyst (view profile)

on 17 Nov 2019 at 17:55
This counts the total number of negative numbers, not the number of rows. You might think what could happen if there are two negative numbers in one or more of the rows (answer in my Answer).
Abdullah Alsuhaymi

### Abdullah Alsuhaymi (view profile)

on 17 Nov 2019 at 19:31
yes , this count the total number of nagative numbers in the matrix but I am looking for number of nagative rows ?
can you help me please ?