MATLAB: How to check whether the strictly positive elements of each row of a matrix are equal

matricesmatrixmatrix arraymatrix manipulation

How can I check whether the strictly positive elements of each row of a matrix are equal? E.g. if
A=[0 1 1 2; 0 1 0 1; 3 0 3 0]
I want
B=[0;1;1]

Best Answer

arrayfun( @(jj) (length(unique(A(jj,(A(jj,:)>0)))) == 1),(1:size(A,1)) )
returns
ans =
0 1 1