%function createMatrix % createMatrix takes a list of scores, one game per line % and creates a matrix of the scores. % Each team has a row and column. % A team's own scores go in their column. % A team's opponents' scores go in the opponents column of the team's row. % Ex. If team i vs team j, team i's score goes in cell[j,i] (row j, column i) % team j's score goes in cell[i,j] (row i, column j). % A non-game is scored 1-1. % % file is the name of the file to take input from. % Each line of input must look exactly like this % % TeamA # TeamB # % One game per line. % The team names can have no spaces. % % Scores is a cell array containing each round of scores % GameIndex tells which games have been played, and also tells % who won each game % games is the number of games % teamnum is the number of teams % Teams is a struct with the team names and assigned team numbers function [Scores,GamesIndex,gamesR,teamnum,Teams] = createMatrixTI(file) % t1, list of teams % s1, list of scores for those teams % t2, list of opponents % s2, list of scores for those opponents teamnum = 1; [t1,s1,t2,s2] = textread(file,'%s %n %s %n'); games = length(t1); gamesR(1) = 0; Teams = struct(t1{1},teamnum); for i=1:length(t1) if(~isfield(Teams,t1{i})) teamnum = teamnum+1; Teams = setfield(Teams,t1{i},teamnum); end if(~isfield(Teams,t2{i})) teamnum = teamnum+1; Teams = setfield(Teams,t2{i},teamnum); end end Scores = cell(1); Scores{1} = ones(teamnum); GamesIndex = cell(1); GamesIndex{1} = zeros(teamnum); for i=1:games round = 1; a = getfield(Teams,t1{i}); b = getfield(Teams,t2{i}); notdone = 1; while(notdone) if(round > length(Scores)) Scores{round} = ones(teamnum); GamesIndex{round} = zeros(teamnum); gamesR(round) = 0; notdone = 0; end if(GamesIndex{round}(a,b) == 0) Scores{round}(b,a) = s1(i); Scores{round}(a,b) = s2(i); GamesIndex{round}(b,a) = 1 -2*(s1(i)