Not Enough Input Arguments in line 2

조회 수: 1 (최근 30일)
Mohammad
Mohammad 2013년 4월 1일
%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
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?
Mohammad
Mohammad 2013년 4월 1일
this is tic tac toe game . can u run this project in your computer??

댓글을 달려면 로그인하십시오.

답변 (2개)

Brian B
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
Mohammad
Mohammad 2013년 4월 1일
plz copy of this code in your mathlab and tell me where the problem is please
Brian B
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
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
Mohammad
Mohammad 2013년 4월 1일
sorry but i cont underestand what did you say. can u explain more
Walter Roberson
Walter Roberson 2013년 4월 1일
Exactly how are you running your code at present?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Entering Commands에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by