MATLAB: Provided a 1D array of integers, find all combinations of 3 values from this set such that: a+b+c=0

arrayshomeworkthree sumvectors

Ok, I can't figure out where I what I am doing wrong in my code. I have tried debugging but without knowing what they are asking me to fix it's kind of hard to just go from that. Any advice on how to correct this would be greatly appreciated.
function [S] = ThreeSum(i, j, k)
for i=0;
i < S;
for j = i + 1;
j < S;
for k = j + 1;
k < S;
if a(i) + a(j) + a(k) == 0;
end
end
end
end
end

Best Answer

if A is your 1D array, than you can use:
B=combntns(A,3);
C=sum(B,2);
D=B(~C,:);