Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- close all
- clear
- clc
- format long g
- % import data
- [num,text,raw] = xlsread('scoresummary.xlsx');
- [rows,cols] = size(raw);
- % get total elapsed time at time of each score
- basetime = 0;
- for n = 1:rows
- % not first quarter AND new quarter
- if n~= 1 && ~strcmp(text{n,1},'')
- % add 15 minutes for new quarter
- basetime = basetime+900;
- end
- % convert from decimal date to time
- % subtracted from 900 because time counts down
- quartertime = 900-(num(n,1)*24*60);
- gametime(n,1) = quartertime + basetime;
- end
- % leading 0 for beginning of the game
- % trailing 3600 and final score for end game
- gametime = [0;gametime;3600];
- t1scoreTimes = [0;num(:,4);num(end,4)];
- t2scoreTimes = [0;num(:,5);num(end,5)];
- diffTimes = [t1scoreTimes-t2scoreTimes];
- % quick and dirty interpolation
- time = [0:3600]';
- n = 1;
- for t = 1:length(time)
- if time(t,1) >= gametime(n+1,1)
- n = n+1;
- end
- t1score(t,1) = t1scoreTimes(n,1);
- t2score(t,1) = t2scoreTimes(n,1);
- diff(t,1) = diffTimes(n,1);
- end
- % integration
- for t = 1:length(time)
- if t ~= 1
- scoreIntegral(t,1) = trapz(time(1:t,1),diff(1:t,1));
- end
- end
- figure(1)
- stairs(time/60,t1score,'b')
- hold on
- stairs(time/60,t2score,'r')
- title('Team score')
- xlabel('time (min)')
- ylabel('points')
- legend('Team 1','Team 2')
- figure(2)
- stairs(time/60,diff,'b')
- hold on
- plot(time/60,scoreIntegral/3600,'r')
- title(['Score differential, game average = ',num2str(scoreIntegral(end,1)/3600)])
- xlabel('time (min)')
- ylabel('points (team 1 - team 2)')
- legend('Score differential','Moving average')
- axis([0 time(end,1)/60 -1.25*max(diff) 1.25*max(diff)])
- figure(3)
- plot(time/60,scoreIntegral/60)
- title('Score differential integral')
- xlabel('time (min)')
- ylabel('point minutes')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement