Not Enough Input Arguments in line 2
1 view (last 30 days)
Show older comments
%I have error in line 2%
function w=sumcheck(s)
if abs(s)==3,
w=1;
if s==3,
disp('X wins')
else
disp('O wins')
end
else
w=0;
end
function w=check(t)
s=0;
for i=1:3
s=s+t(i,i);
end
w=sumcheck(s);
if w==0
s=0;
for i=1:3
s=s+t(i,4-i);
end
w=sumcheck(s);
end
if w==0
for i= 1:3
if w==1, break
else
s=0;
for j=1:3
s=s+t(i,j);
end
w=sumcheck(s);
end
end
end
if w==0
for i=1:3
if w==1,break
else
s=0;
for j=1:3
s=s+t(j+i);
end
w=sumcheck(s);
end
end
end
if w==0
disp('draw')
end
t=randi([-1 1],3,3);
for z= 1:3
b=t(:,z);
check(b)
end
for y=1:3
c=[t(x,:,1);t(x,:,2)];
check(c)
end
for x=1:3
r=[t(x,:,1);t(x,:,2)];
check(r)
end
s=s+t(1,1,1)+t(2,2,2);
w=sumcheck(s);
ss+t(1,3)+t(2,2);
w=sumcheck(s);
s=s+t(3,1)+t(2,2);
w=sumcheck(s);
s=s+t(3,3)+t(2,2);
2 Comments
Kevin Claytor
on 1 Apr 2013
... What are you trying to do? And where is the problem? You have a lot of functions in there - which is giving you the issue?
Answers (2)
Brian B
on 1 Apr 2013
Edited: Brian B
on 1 Apr 2013
You need to call this function with an input argument, as in:
sumcheck(1)
Of course, this is just an example. I have no idea (because I didn't read the rest of the code) what kind of argument it expects.
2 Comments
Brian B
on 1 Apr 2013
Sorry; I'm willing to help you understand problems you find. I won't debug it for you.
We've already pointed out the cause of the error you describe: this code is a function, not a script. So you need to call it with arguments, as I wrote above.
Did you try that? What happened? What should have happened? Do you know what input you ought to give?
Walter Roberson
on 1 Apr 2013
You cannot run those routines by pressing F5 or clicking on "run" in the menus. Instead, at the command line, you must type in
check(t)
where t is the matrix of values you want to run the program with, such as
check([11 48 153234 83 17])
2 Comments
See Also
Categories
Find more on Entering Commands in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!