Not Enough Input Arguments in line 2
1 次查看(过去 30 天)
显示 更早的评论
%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 个评论
Kevin Claytor
2013-4-1
... 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?
回答(2 个)
Brian B
2013-4-1
编辑:Brian B
2013-4-1
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 个评论
Brian B
2013-4-1
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
2013-4-1
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Entering Commands 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!