Info
This question is closed. Reopen it to edit or answer.
HELP!!!setting up function keep getting error not enough input arguements
1 view (last 30 days)
Show older comments
I am trying to set up a function to give me the season record wins and losses but keep getting an error.... here is what i have so far:
function [ number_of_auburn_wins, number_of_auburn_loss ] = printSeasonRecord(game,month,auscore, oscore)
number_of_auburn_wins= 0;
number_of_auburn_loss=0;
for game=1:size(month);
if auscore(game) > oscore(game)
win_or_loss(game) = 'W';
number_of_auburn_wins = number_of_auburn_wins + 1;
else
win_or_loss(game) = 'L';
number_of_auburn_loss= number_of_auburn_loss +1;
end
end
please help!!!
0 Comments
Answers (3)
Image Analyst
on 10 Apr 2013
Edited: Image Analyst
on 10 Apr 2013
What is the purpose of the "month" variable? Why does a function called printSeasonRecord() not print anything? Why are you not initializing number_of_auburn_wins and number_of_auburn_loss? Why do you need two of them? Why do some of the indexes go unassigned? Why not just say
number_of_auburn_wins = sum(auscore > oscore);
number_of_auburn_loss = length(month) - number_of_auburn_wins;
and not worry about that loop at all?
5 Comments
Yao Li
on 10 Apr 2013
I guess what he really needs is the results of each match with detailed information, eg. date of the match,opponets etc.
Walter Roberson
on 10 Apr 2013
Once the function gets launch, if there were not at least two arguments passed to the function, you would get the "not enough input arguments" error when you reached size(month) . If 2 or 3 arguments were passed in but not 4, then that error would be reached on the next line.
If 4 arguments were being passed in, then the error could occur if the arguments auscore or oscore were function handles for functions that take at least two arguments.
Yao Li
on 10 Apr 2013
game is an input argument of the function but game is defined in the for loop again. I don't think it's good.
0 Comments
Walter Roberson
on 10 Apr 2013
for game=1:size(month)
is not going to give you the result you expect. size() returns a vector with at least 2 elements. When you use a vector as one of the operands of the colon operator, you will get a warning. If you know the colon operator well enough to know what the result will be, then you also know the size() and length() operators well enough to know how to return the appropriate scalar for your purpose.
0 Comments
This question is closed.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!