Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

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

1 Ansicht (letzte 30 Tage)
Ashley
Ashley am 10 Apr. 2013
Geschlossen: MATLAB Answer Bot am 20 Aug. 2021
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!!!

Antworten (3)

Image Analyst
Image Analyst am 10 Apr. 2013
Bearbeitet: Image Analyst am 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 Kommentare
Yao Li
Yao Li am 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
Walter Roberson am 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
Yao Li am 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.

Walter Roberson
Walter Roberson am 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.

Diese Frage ist geschlossen.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by