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

답변 (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

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.
Yao Li
Yao Li 2013년 4월 10일

0 개 추천

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.

이 질문은 마감되었습니다.

태그

질문:

2013년 4월 10일

마감:

2021년 8월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by