Not Enough Input Arguments in line 2

1 Ansicht (letzte 30 Tage)
Mohammad
Mohammad am 1 Apr. 2013
%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 Kommentare
Kevin Claytor
Kevin Claytor am 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?
Mohammad
Mohammad am 1 Apr. 2013
this is tic tac toe game . can u run this project in your computer??

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Brian B
Brian B am 1 Apr. 2013
Bearbeitet: Brian B am 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 Kommentare
Mohammad
Mohammad am 1 Apr. 2013
plz copy of this code in your mathlab and tell me where the problem is please
Brian B
Brian B am 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?

Melden Sie sich an, um zu kommentieren.


Walter Roberson
Walter Roberson am 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 Kommentare
Mohammad
Mohammad am 1 Apr. 2013
sorry but i cont underestand what did you say. can u explain more
Walter Roberson
Walter Roberson am 1 Apr. 2013
Exactly how are you running your code at present?

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by