MATLAB: 3 Sum problem,

3sum

Hey guys, I'm learning how to do matlab right now and I've run into a problem. I'm trying a unique way of solving a 3Sum problem, and am having trouble getting this to execute properly. I've debugged it but I'm still having issues. This isn't the final version but I'm having issues creating a function from which the randsamples can be used. Here's the code.
F = randi ([-10,10],1,20);
sort (F)
for t = 0;
func t = (a + b + c);
a = randsample (20,1,REPLACE);
b = randsample (20,1,REPLACE);
c = randsample (20,1,REPLACE);
if (t == 0);
output [ a b c ];
exit
end
end
I know I'm really new at this, I just need some help and my teacher's out of town. Thanks guys!
EDIT: Alright so I took some stuff out and now I'm down to this. For some reason though, it's just coming up with random numbers from the array instead of using them to find a 1D array which adds to zero.
F = [-5,-4,-3,-2,-1,1,2,3,4,5];
for T = @(a,b,c) (a + b + c);
a = randsample (F,1);
b = randsample (F,1);
c = randsample (F,1);
if T(a,b,c) == 0
disp [a b c]
end
end

Best Answer

Your line
func t = (a + b + c);
would either be rejected as invalid syntax, or else would be interpreted as a request to call the function named "func" with the parameters 't', '=', '(a', '+', 'b', '+', 'c)'
Perhaps you meant something like
T = @(a,b,c) (a + b + c);
a = ...
b = ...
c = ...
if T(a,b,c) == 0
output([a b c]);
exit
end
But if so, we would wonder why you bother to calculate F since you do not use it, and we would wonder why you bother to create a "for" loop that is going to be executed only once, "for t = 0".
I would also point out that if you randomly sample the integers from 1 to 20, as in your randsample() calls, then none of the values can be 0 or negative and so their sum cannot be less than 3, which will never equal 0, and thus the array or function "output" will not be used. What is "output" anyhow? It is not a MATLAB built-in routine.