MATLAB: Finding all possible row combinations of a matrix that add to zero

combinationsmatrixmatrix manipulation

Hello,
I'm looking for a general way to find all possible row combinations of a matrix that add to zero.
For instance, for the matrix
A = [-1 0 0 ; 1 0 0 ; 1 -1 0 ; 0 1 -1 ; 0 1 -1; 0 0 1];
the following 6 row combinations would all sum to zero
A(1,:)+A(2,:)
A(1,:)+A(3,:)+A(4,:)+A(6,:)
A(1,:)+A(3,:)+A(5,:)+A(6,:)
-A(2,:)+A(3,:)+A(4,:)+A(6,:)
-A(2,:)+A(3,:)+A(5,:)+A(6,:)
-A(4,:)+A(5,:)
Does MATLAB have any built-in functions that can help me do this? Generating all possible row combinations and testing to see which ones sum to zero seems like it would be extremely computationally intensive.
Thanks,
Kevin

Best Answer

Edit2
A = [-1 0 0 ; 1 0 0 ; 1 -1 0 ; 0 1 -1 ; 0 1 -1; 0 0 1];
n=size(A,1);
idx=logical(npermutek([0 1],n));
p=size(idx,1);
out=cell(p,1);
for k=1:p
out{k}=sum(A(idx(k,:),:),1);
end
You can get you sum in a matrix 647x3
M=cell2mat(out)