function rankSeason(its,fromfile,tofile) [S,GI,games,teams,Teams] = creatematrixTI(fromfile); % S stands for scores %S has a row and column for every team. %A teams own scores go in their column. %A teams opponents scores go in their row. %Ex. If team i vs team j, team i's score goes in cell[j,i] % team j's score goes in cell[i,j] % A non-game is scored 1-1. TotMgn = 0; TotScores = 0; Ranks = zeros(1,teams); % Vector of team's ranks Games = zeros(1,teams); % Vector of team's games played Diffs = zeros(teams); % A matrix containing the difference in ranks rounds = length(S); SOV = cell(1,rounds); GamesIndices = cell(1,rounds); for r=1:rounds TotScores = TotScores + sum(sum(S{r})) - teams - 2*games(r); TotMgn = TotMgn + sum(sum(abs(S{r}-S{r}.')))/2; AvStrength = TotMgn/TotScores; %OwnScore - OppScore/TotalScoreOfGame SOV{r} = ((S{r}-S{r}.')./(S{r}+S{r}.')); GamesIndices{r} = abs(GI{r}); end % GIs is a matrix denoting any game thats been played. GIs = GamesIndices{1}; for r=2:rounds GIs = or(GIs,GamesIndices{r}); end for i=1:its for j=1:teams Diffs(:,j) = Ranks(j)*GIs(:,j)... - (Ranks.*GIs(j,:)).'; end stddev = std_dev(Diffs) if(stddev ~= 0) for r=1:rounds Ranks = Ranks + sum(SOV{r}... - (AvStrength/stddev)*(Diffs.*GamesIndices{r})); end else for r=1:rounds Ranks = Ranks + sum(SOV{r}); end end end end [Y,Order] = sort(Ranks); ts = fieldnames(Teams); fid = fopen(tofile,'w'); for i=teams:-1:1 fprintf(fid,'%i & %s &\\\\ \n',teams-i+1,ts{Order(i)}); end fclose(fid);