Question: hey so i have this Colley Method MATLAB code, but I want to implement some code where if the team wins an away game it

hey so i have this Colley Method MATLAB code, but I want to implement some code where if the team wins an away game it is rated higher than if they win at home.

The .txt files used in the code can be found on masseyratings.com and is the NCAA DI BASKETBALL.

here is the MATLAB code.

function ColleyRanking_NoWeight

'2018games.txt'; '2018teams.txt'; 10;

% EXAMPLE INPUT:

% ColleyRanking_NoWeight('2018games.txt','2018teams.txt', 10);

% k = scalar for number of top ranked teams to list

k = 10;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Load the team names into an array

fid = fopen('2018teams.txt');

counter = 0;

teamname = fgetl(fid); % fgetl reads a single line

while (ischar(teamname)) % ischar(A) returns logical 1 (true) if A is a character array

counter = counter + 1;

[token, remain] = strtok(teamname); teamname = strtok(remain);

teamname=cellstr(teamname);

teamNames(counter) = teamname;

teamname = fgetl(fid);

end

fclose(fid);

numTeams = counter;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Load the games

games=load('2018games.txt');

% columns of games are:

% column 1 = days since 1/1/0000

% column 2 = date in YYYYMMDD format

% column 3 = team1 index

% column 4 = team1 homefield (1 = home, -1 = away, 0 = neutral)

% column 5 = team1 score

% column 6 = team2 index

% column 7 = team2 homefield (1 = home, -1 = away, 0 = neutral)

% column 8 = team2 score

numGames = size(games, 1);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Calculate the Wins, Losses, and the matrix C

C = zeros(numTeams, numTeams);

Wins = zeros(numTeams,1);

Losses = zeros(numTeams,1);

for i=1:numGames

team1ID = games(i, 3);

team1Score = games(i, 5);

team2ID = games(i, 6);

team2Score = games(i, 8);

team1HA = games(i,4);

team2HA = games(i,7);

C(team2ID, team1ID) = C(team2ID, team1ID) - 1;

C(team1ID, team2ID) = C(team2ID, team1ID);

% Team 1 always wins in data set

Wins(team1ID) = Wins(team1ID) + 1;

Losses(team2ID) = Losses(team2ID) + 1;

end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Calculate linear system

diagC = 2 + Wins + Losses;

C = C + diag(diagC);

b = 1 + .5*(Wins-Losses);

r = C\b;

[sortedr,index]=sort(r,'descend');

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Statistics to Output to Screen

fprintf(' ************** COLLEY Rating Method ************** ');

fprintf('=========================== ');

fprintf('Results for Top %d Teams ',k);

fprintf('=========================== ');

fprintf('Rank Rating Team ');

fprintf('=========================== ');

for i=1:k

fprintf('%4d %8.5f %s ',i,sortedr(i),cell2mat(teamNames(index(i))));

end

fprintf(' '); % extra carriage return

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!