%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] = createMatrixTD(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; GC = cell(4,length(file)); for k=1:length(file) [GC{1,k},GC{2,k},GC{3,k},GC{4,k}] =... textread(file{k},'%s %n %s %n'); gamesR(k) = length(GC{1,k}); if(k==1) Teams = struct(GC{1,k}{1},teamnum); end for i=1:length(GC{1,k}) if(~isfield(Teams,GC{1,k}{i})) teamnum = teamnum+1; Teams = setfield(Teams,GC{1,k}{i},teamnum); end if(~isfield(Teams,GC{3,k}{i})) teamnum = teamnum+1; Teams = setfield(Teams,GC{3,k}{i},teamnum); end end end Scores = cell(1,k); GamesIndex = cell(1,k); for k=1:length(file) Scores{k} = ones(teamnum); GamesIndex{k} = zeros(teamnum); for i=1:gamesR(k) a = getfield(Teams,GC{1,k}{i}); b = getfield(Teams,GC{3,k}{i}); if(GamesIndex{k}(a,b) == 0) Scores{k}(b,a) = GC{2,k}(i); Scores{k}(a,b) = GC{4,k}(i); GamesIndex{k}(b,a) = 1 -2*(GC{2,k}(i)