Info

此问题已关闭。 请重新打开它进行编辑或回答。

HELP!!!setting up function keep getting error not enough input arguements

1 次查看(过去 30 天)
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!!!

回答(3 个)

Image Analyst
Image Analyst 2013-4-10
编辑:Image Analyst 2013-4-10
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 个评论
Yao Li
Yao Li 2013-4-10
I guess what he really needs is the results of each match with detailed information, eg. date of the match,opponets etc.
Walter Roberson
Walter Roberson 2013-4-10
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
Yao Li 2013-4-10
game is an input argument of the function but game is defined in the for loop again. I don't think it's good.

Walter Roberson
Walter Roberson 2013-4-10
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.

此问题已关闭。

标签

Community Treasure Hunt

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

Start Hunting!

Translated by