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) == 0disp [a b c]endend
Best Answer