ATN
ATN

Reputation: 23

Number of the positive (> 0) values in each row of a matrix

Considering A = a 100 by 5 matrix of random integers between 􀀀-100 and 100, I would like to find B = the number of the positive (>= 0) values in each row of A using sum (no loops).

B=sum(rint(:)>0) does not seem right as it only gives me the total number of positive values of the whole matrix.

How do I get the values for each row?

Thank you!

Upvotes: 0

Views: 106

Answers (1)

Ander Biguri
Ander Biguri

Reputation: 35525

You can use B=sum(rint>0) to get the sum of the columns, and B=sum(rint>0,2) to get the ones of the row. Sum accepts a second argument to define the dimension on which you are summing.

Upvotes: 2

Related Questions