Advertisement
Guest User

Untitled

a guest
Jan 26th, 2015
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.80 KB | None | 0 0
  1. close all
  2. clear
  3. clc
  4. format long g
  5.  
  6. % import data
  7. [num,text,raw] = xlsread('scoresummary.xlsx');
  8. [rows,cols] = size(raw);
  9.  
  10. % get total elapsed time at time of each score
  11. basetime = 0;
  12. for n = 1:rows
  13.     % not first quarter AND new quarter
  14.     if n~= 1 && ~strcmp(text{n,1},'')
  15.         % add 15 minutes for new quarter
  16.         basetime = basetime+900;
  17.     end
  18.    
  19.     % convert from decimal date to time
  20.     % subtracted from 900 because time counts down
  21.     quartertime = 900-(num(n,1)*24*60);
  22.     gametime(n,1) = quartertime + basetime;
  23. end
  24.  
  25. % leading 0 for beginning of the game
  26. % trailing 3600 and final score for end game
  27. gametime = [0;gametime;3600];
  28. t1scoreTimes = [0;num(:,4);num(end,4)];
  29. t2scoreTimes = [0;num(:,5);num(end,5)];
  30. diffTimes = [t1scoreTimes-t2scoreTimes];
  31.  
  32. % quick and dirty interpolation
  33. time = [0:3600]';
  34. n = 1;
  35. for t = 1:length(time)
  36.     if time(t,1) >= gametime(n+1,1)
  37.         n = n+1;
  38.     end
  39.    
  40.     t1score(t,1) = t1scoreTimes(n,1);
  41.     t2score(t,1) = t2scoreTimes(n,1);
  42.     diff(t,1) = diffTimes(n,1);
  43. end
  44.  
  45. % integration
  46. for t = 1:length(time)
  47.     if t ~= 1
  48.         scoreIntegral(t,1) = trapz(time(1:t,1),diff(1:t,1));
  49.     end
  50. end
  51.  
  52. figure(1)
  53. stairs(time/60,t1score,'b')
  54. hold on
  55. stairs(time/60,t2score,'r')
  56. title('Team score')
  57. xlabel('time (min)')
  58. ylabel('points')
  59. legend('Team 1','Team 2')
  60.  
  61. figure(2)
  62. stairs(time/60,diff,'b')
  63. hold on
  64. plot(time/60,scoreIntegral/3600,'r')
  65. title(['Score differential, game average = ',num2str(scoreIntegral(end,1)/3600)])
  66. xlabel('time (min)')
  67. ylabel('points (team 1 - team 2)')
  68. legend('Score differential','Moving average')
  69. axis([0 time(end,1)/60 -1.25*max(diff) 1.25*max(diff)])
  70.  
  71. figure(3)
  72. plot(time/60,scoreIntegral/60)
  73. title('Score differential integral')
  74. xlabel('time (min)')
  75. ylabel('point minutes')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement