MATLAB: Size of nonzero entries in each row of a matrix without loop

MATLABno loopnonzero

Let's explained with an example if I have h =
0 1 2 3
1 0 0 0
5 0 1 0
there is any function that will return the number of nonzero elements per row something like c =
3
1
2
but without a loop. I know I can use nnz per row
something like
for i=1: numRows
c(i)=nnz(h(i,:));
end
but there is any way to do it without a loop?
I will really appreciate any suggestions

Best Answer

c = sum(h~=0,2);