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 Center および File ExchangeEntering Commands についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by