MATLAB: Find rows with all but one nonzero element

nonzeroszeros

hi,
after some calculation i get a matrix for example like this-
A=[1 0 1 1; 0 1 1 0; 1 0 1 0; 0 0 1 0]
now from A i want to output the row with all but one nonzero element
B=[0 0 1 0]
which will be the 4th row in this example.
how do i do it?

Best Answer

Here's one way:
A(sum(A,2)==1,:)