MATLAB: Calculate the number of nonzero rows

nonzero rows

Hi,
How can I calculate the number of nonzero rows in a matrix?
I have
B =
3 4
5 0
0 0
and the number of nonzero rows (that I need) is 2. (because the 2nd row has the element of '5')
I tried sum( all( B ~= 0, 2 ) ); but the answer is 1.

Best Answer

>> nnz(any(B,2))
ans = 2