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

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!!!

Answers (3)

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

All you need is:
function number_of_auburn_wins = printSeasonRecord(auscore, oscore)
number_of_auburn_wins = sum(auscore > oscore);
that's it. Nothing else is needed.
I am still getting not enough input arguements...
How are you calling the function? Are you supplying the input arguments?
I guess what he really needs is the results of each match with detailed information, eg. date of the match,opponets etc.
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.
game is an input argument of the function but game is defined in the for loop again. I don't think it's good.
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.

This question is closed.

Tags

Asked:

on 10 Apr 2013

Closed:

on 20 Aug 2021

Community Treasure Hunt

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

Start Hunting!