{"id":1996,"date":"2013-01-07T14:58:51","date_gmt":"2013-01-07T19:58:51","guid":{"rendered":"https:\/\/blogs.mathworks.com\/community\/?p=1996"},"modified":"2013-01-25T13:35:06","modified_gmt":"2013-01-25T18:35:06","slug":"football-squares-with-matlab","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/community\/2013\/01\/07\/football-squares-with-matlab\/","title":{"rendered":"Football Squares with MATLAB"},"content":{"rendered":"<!DOCTYPE html\r\n  PUBLIC \"-\/\/W3C\/\/DTD HTML 4.01 Transitional\/\/EN\">\r\n<style type=\"text\/css\">\r\n\r\nh1 { font-size:18pt; }\r\nh2.titlebg { font-size:13pt; }\r\nh3 { color:#4A4F55; padding:0px; margin:5px 0px 5px; font-family:Arial, Helvetica, sans-serif; font-size:11pt; font-weight:bold; line-height:140%; border-bottom:1px solid #d6d4d4; display:block; }\r\nh4 { color:#4A4F55; padding:0px; margin:0px 0px 5px; font-family:Arial, Helvetica, sans-serif; font-size:10pt; font-weight:bold; line-height:140%; border-bottom:1px solid #d6d4d4; display:block; }\r\n   \r\np { padding:0px; margin:0px 0px 20px; }\r\nimg { padding:0px; margin:0px 0px 20px; border:none; }\r\np img, pre img, tt img, li img { margin-bottom:0px; } \r\n\r\nul { padding:0px; margin:0px 0px 20px 23px; list-style:square; }\r\nul li { padding:0px; margin:0px 0px 7px 0px; background:none; }\r\nul li ul { padding:5px 0px 0px; margin:0px 0px 7px 23px; }\r\nul li ol li { list-style:decimal; }\r\nol { padding:0px; margin:0px 0px 20px 0px; list-style:decimal; }\r\nol li { padding:0px; margin:0px 0px 7px 23px; list-style-type:decimal; }\r\nol li ol { padding:5px 0px 0px; margin:0px 0px 7px 0px; }\r\nol li ol li { list-style-type:lower-alpha; }\r\nol li ul { padding-top:7px; }\r\nol li ul li { list-style:square; }\r\n\r\npre, tt, code { font-size:12px; }\r\npre { margin:0px 0px 20px; }\r\npre.error { color:red; }\r\npre.codeinput { padding:10px; border:1px solid #d3d3d3; background:#f7f7f7; }\r\npre.codeoutput { padding:10px 11px; margin:0px 0px 20px; color:#4c4c4c; }\r\n\r\n@media print { pre.codeinput, pre.codeoutput { word-wrap:break-word; width:100%; } }\r\n\r\nspan.keyword { color:#0000FF }\r\nspan.comment { color:#228B22 }\r\nspan.string { color:#A020F0 }\r\nspan.untermstring { color:#B20000 }\r\nspan.syscmd { color:#B28C00 }\r\n\r\n.footer { width:auto; padding:10px 0px; margin:25px 0px 0px; border-top:1px dotted #878787; font-size:0.8em; line-height:140%; font-style:italic; color:#878787; text-align:left; float:none; }\r\n.footer p { margin:0px; }\r\n\r\n  <\/style><div class=\"content\"><h3>Contents<\/h3><div><ul><li><a href=\"#8c9e5dad-68bb-46b1-a0e7-65bdefbfa3d4\">Super Bowl Squares<\/a><\/li><li><a href=\"#f037784c-a846-4abb-869c-dac0badec9f0\">Get the Data<\/a><\/li><li><a href=\"#37cc7e96-10c0-44ad-92fa-ac940e86d943\">Regular Expressions to the Rescue!<\/a><\/li><li><a href=\"#393b42da-4eb2-4ab8-bcbb-d9fd5ba13c03\">Populate the Results Matrix<\/a><\/li><li><a href=\"#c303e8ed-3c40-46e9-9182-895412e5461f\">Compute the Probability Matrix<\/a><\/li><li><a href=\"#e6bcb479-ed02-470e-8a77-1734081a9d44\">Add Numbers to the Plot<\/a><\/li><li><a href=\"#f5119a8d-cfb6-4e1c-b8f1-23679bbccb6b\">The Bottom Line<\/a><\/li><\/ul><\/div><h4>Super Bowl Squares<a name=\"8c9e5dad-68bb-46b1-a0e7-65bdefbfa3d4\"><\/a><\/h4><p><a href=\"https:\/\/blogs.mathworks.com\/community\/2012\/11\/20\/england-football-and-comma-separated-tables\/\">In my last post<\/a> I wrote about English football. This time I'm talking about the American version. Here in the U.S. it's playoff season for professional football, and that means greasy food, beer, big-screen televisions, and football squares.<\/p><p>And what are football squares, you may ask? It's a simple mechanism to let a group of people wager on the outcome of a ballgame. Consider the following plot.<\/p><pre class=\"codeinput\">a = invhilb(10)&lt;0;\r\n<span class=\"comment\">% Why invhilb? See this Cody problem:<\/span>\r\n<span class=\"comment\">%   https:\/\/www.mathworks.com\/matlabcentral\/cody\/problems\/4-make-a-checkerboard-matrix<\/span>\r\ntick = 0:9;\r\nimagesc(tick,tick,a)\r\ncolormap([1; 0.8]*[1 1 1])\r\nset(gca, <span class=\"keyword\">...<\/span>\r\n    <span class=\"string\">'XAxisLocation'<\/span>,<span class=\"string\">'top'<\/span>, <span class=\"keyword\">...<\/span>\r\n    <span class=\"string\">'XTick'<\/span>,tick, <span class=\"keyword\">...<\/span>\r\n    <span class=\"string\">'YTick'<\/span>,tick)\r\naxis <span class=\"string\">square<\/span>\r\nxlabel(<span class=\"string\">'Last Digit of Team A''s Score'<\/span>)\r\nylabel(<span class=\"string\">'Last Digit of Team B''s Score'<\/span>)\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/community\/files\/squares_01.png\" alt=\"\"> <p>It has 100 small squares in it, each one corresponding to a pair of one-digit numbers. These one-digit numbers, in turn, correspond to the last digit in the final score of one of the two teams. Before the game, everyone buys one or more squares until they've all been sold. Now, if the Alligators (team A) go on to defeat the Buckaroos (team B) 17-10, then the owner of the square at location (7,0) would be the winner.<\/p><p>As you can imagine, some score pairs are much more likely than others. For this reason, in practice the squares are usually sold off at random. You don't get to pick which score pair you will receive.<\/p><p>All this sets the scene for a Super Bowl party from a few years ago. The Green Bay Packers were playing the Pittsburgh Steelers, and I had acquired a square. But not just any square. My square was linked to the score pair (2,2).<\/p><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/community\/files\/football-squares.png\" alt=\"\"> <\/p><p>This struck me as a rare score pair. But how rare? Being quantitatively minded, and armed with my favorite technical computing tool, I went looking for data.<\/p><p>A little web searching turned up a site with <a href=\"#game_scores::none\">every single NFL football game played since 1920<\/a>, nearly 15,000 games. A savvy reader may observe that the game has changed a lot during that interval. Nevermind that! Let's do the calculations and see what we get.<\/p><h4>Get the Data<a name=\"f037784c-a846-4abb-869c-dac0badec9f0\"><\/a><\/h4><p>First grab the HTML.<\/p><pre class=\"codeinput\">url = <span class=\"string\">'#game_scores::none'<\/span>;\r\nhtml = urlread(url);\r\n<\/pre><h4>Regular Expressions to the Rescue!<a name=\"37cc7e96-10c0-44ad-92fa-ac940e86d943\"><\/a><\/h4><p>By carefully examining the structure of the HTML, we can make a regular expression target that will extract the information we need.<\/p><pre class=\"codeinput\">target = [ <span class=\"keyword\">...<\/span>\r\n    <span class=\"string\">'&lt;tr  class=\"\"&gt;\\s*'<\/span> <span class=\"keyword\">...<\/span>\r\n    <span class=\"string\">'&lt;td align=\"right\"  csk.*?&gt;.*?&lt;\/td&gt;\\s*'<\/span> <span class=\"keyword\">...<\/span>\r\n    <span class=\"string\">'&lt;td align=\"right\"  csk.*?&gt;.*?&lt;\/td&gt;\\s*'<\/span> <span class=\"keyword\">...<\/span>\r\n    <span class=\"string\">'&lt;td align=\"right\" &gt;(\\d+)&lt;\/td&gt;\\s*'<\/span> <span class=\"keyword\">...<\/span>\r\n    <span class=\"string\">'&lt;td align=\"right\" &gt;(\\d+)&lt;\/td&gt;\\s*'<\/span> <span class=\"keyword\">...<\/span>\r\n    <span class=\"string\">'&lt;td align=\"right\" &gt;\\d+&lt;\/td&gt;\\s*'<\/span> <span class=\"keyword\">...<\/span>\r\n    <span class=\"string\">'&lt;td align=\"right\" &gt;\\d+&lt;\/td&gt;\\s*'<\/span> <span class=\"keyword\">...<\/span>\r\n    <span class=\"string\">'&lt;td align=\"right\"  csk.*?&gt;&lt;a href=\".*?\"&gt;(\\d+)&lt;\/a&gt;&lt;\/td&gt;\\s*'<\/span> <span class=\"keyword\">...<\/span>\r\n    ];\r\ntk = regexp(html,target,<span class=\"string\">'tokens'<\/span>);\r\n<\/pre><h4>Populate the Results Matrix<a name=\"393b42da-4eb2-4ab8-bcbb-d9fd5ba13c03\"><\/a><\/h4><p>Armed with the textual data from the HTML, we can insert it into a matrix with counts for all the possible outcomes.<\/p><pre class=\"codeinput\">score = zeros(100);\r\noneDigitScore = zeros(10);\r\n\r\n<span class=\"keyword\">for<\/span> i = 1:length(tk)\r\n    winning = str2num(tk{i}{1});\r\n    winningMod10 = mod(winning,10);\r\n    losing = str2num(tk{i}{2});\r\n    losingMod10 = mod(losing,10);\r\n    game_count = str2num(tk{i}{3});\r\n\r\n    <span class=\"comment\">% 100-by-100 score grid with actual final scores<\/span>\r\n    score(winning+1,losing+1) = game_count;\r\n\r\n    <span class=\"comment\">% 10-by-10 score grid with mod 10 final scores<\/span>\r\n    oneDigitScore(winningMod10+1,losingMod10+1) = oneDigitScore(winningMod10+1,losingMod10+1) + game_count\/2;\r\n    oneDigitScore(losingMod10+1,winningMod10+1) = oneDigitScore(losingMod10+1,winningMod10+1) + game_count\/2;\r\n\r\n<span class=\"keyword\">end<\/span>\r\n<\/pre><h4>Compute the Probability Matrix<a name=\"c303e8ed-3c40-46e9-9182-895412e5461f\"><\/a><\/h4><p>Calculate percentages based on the total number of games and visualize the results.<\/p><pre class=\"codeinput\">prob = oneDigitScore\/sum(oneDigitScore(:))*100;\r\nimagesc(0:9,0:9,prob)\r\ncolormap(summer(64))\r\ncolorbar\r\n\r\nset(gca, <span class=\"keyword\">...<\/span>\r\n    <span class=\"string\">'XAxisLocation'<\/span>,<span class=\"string\">'top'<\/span>, <span class=\"keyword\">...<\/span>\r\n    <span class=\"string\">'XTick'<\/span>,tick, <span class=\"keyword\">...<\/span>\r\n    <span class=\"string\">'YTick'<\/span>,tick)\r\naxis <span class=\"string\">square<\/span>\r\nxlabel(<span class=\"string\">'Last Digit of Team A''s Score'<\/span>)\r\nylabel(<span class=\"string\">'Last Digit of Team B''s Score'<\/span>)\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/community\/files\/squares_02.png\" alt=\"\"> <p>Just to be safe, let's verify that the sum of the probability matrix is 100%.<\/p><pre class=\"codeinput\">fprintf(<span class=\"string\">'Sum of all probabilities (percent): %2.1f\\n'<\/span>,sum(prob(:)));\r\n<\/pre><pre class=\"codeoutput\">Sum of all probabilities (percent): 100.0\r\n<\/pre><h4>Add Numbers to the Plot<a name=\"e6bcb479-ed02-470e-8a77-1734081a9d44\"><\/a><\/h4><p>No surprise: the likeliest outcome is the pair (7,0) or (0,7). What about (2,2)? It's looking pretty grim. Let's throw some numbers on the plot to find out.<\/p><pre class=\"codeinput\">colorbar <span class=\"string\">off<\/span>\r\n\r\n[rows,cols] = size(prob);\r\n<span class=\"keyword\">for<\/span> i = 1:rows\r\n  <span class=\"keyword\">for<\/span> j = 1:cols\r\n    text(j-1,i-1,sprintf(<span class=\"string\">'%1.2f'<\/span>,prob(i,j)),<span class=\"keyword\">...<\/span>\r\n        <span class=\"string\">'FontSize'<\/span>, 8, <span class=\"keyword\">...<\/span>\r\n      <span class=\"string\">'Color'<\/span>,<span class=\"string\">'red'<\/span>, <span class=\"keyword\">...<\/span>\r\n      <span class=\"string\">'HorizontalAlignment'<\/span>,<span class=\"string\">'center'<\/span>);\r\n  <span class=\"keyword\">end<\/span>\r\n<span class=\"keyword\">end<\/span>\r\n\r\nset(gca,<span class=\"string\">'XAxisLocation'<\/span>,<span class=\"string\">'top'<\/span>)\r\nxlabel(<span class=\"string\">'Last Digit of Steelers Score'<\/span>)\r\nylabel(<span class=\"string\">'Last Digit of Packers Score'<\/span>)\r\n\r\npatch([2 3 3 2 2]-0.5,[2 2 3 3 2]-0.5,<span class=\"string\">'red'<\/span>, <span class=\"keyword\">...<\/span>\r\n  <span class=\"string\">'FaceColor'<\/span>,<span class=\"string\">'none'<\/span>,<span class=\"string\">'LineWidth'<\/span>,2,<span class=\"string\">'EdgeColor'<\/span>,<span class=\"string\">'yellow'<\/span>)\r\npatch([5 6 6 5 5]-0.5,[1 1 2 2 1]-0.5,<span class=\"string\">'red'<\/span>, <span class=\"keyword\">...<\/span>\r\n  <span class=\"string\">'FaceColor'<\/span>,<span class=\"string\">'none'<\/span>,<span class=\"string\">'LineWidth'<\/span>,2,<span class=\"string\">'EdgeColor'<\/span>,<span class=\"string\">'yellow'<\/span>)\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/community\/files\/squares_03.png\" alt=\"\"> <p>Ouch!<\/p><h4>The Bottom Line<a name=\"f5119a8d-cfb6-4e1c-b8f1-23679bbccb6b\"><\/a><\/h4><p>All this is a long-winded way of saying that my pick, (2,2), is the absolute worst possible choice. Since the merger in 1970, there have been <i>exactly two games<\/i> that ended with (2,2). On December 5, 2004, the Buffalo Bills beat the Miami Dolphins 42-32, and on November 4, 2012 the Tampa Bay Buccaneers defeated the Oakland Raiders by the same score.<\/p><p>Incidentally, the actual winning result for Steelers-Packers Super Bowl, (1,5), is also quite rare. Rare as these things go, but still eleven times more likely than (2,2).<\/p><p>Not that I'm bitter about it.<\/p>\r\n\r\n<h4>Addendum<\/h4>\r\n<p>\r\nLATE ADDITION: In the comments below, Sean and Matt banter about soccer scores and the Football Squares game. Here is the plot that results from English Premier League games (partial season). Numbers shown are percentages.\r\n<\/p>\r\n\r\n<p><img decoding=\"async\" loading=\"lazy\" hspace=\"5\" vspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/community\/files\/soccer-squares.png\" alt=\"\" title=\"soccer-squares\" width=\"393\" height=\"391\" class=\"alignnone size-full wp-image-2074\" \/><\/p>\r\n\r\n<script language=\"JavaScript\"> <!-- \r\n    function grabCode_c52d932239354ddabeadec30b05742fe() {\r\n        \/\/ Remember the title so we can use it in the new page\r\n        title = document.title;\r\n\r\n        \/\/ Break up these strings so that their presence\r\n        \/\/ in the Javascript doesn't mess up the search for\r\n        \/\/ the MATLAB code.\r\n        t1='c52d932239354ddabeadec30b05742fe ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' c52d932239354ddabeadec30b05742fe';\r\n    \r\n        b=document.getElementsByTagName('body')[0];\r\n        i1=b.innerHTML.indexOf(t1)+t1.length;\r\n        i2=b.innerHTML.indexOf(t2);\r\n \r\n        code_string = b.innerHTML.substring(i1, i2);\r\n        code_string = code_string.replace(\/REPLACE_WITH_DASH_DASH\/g,'--');\r\n\r\n        \/\/ Use \/x3C\/g instead of the less-than character to avoid errors \r\n        \/\/ in the XML parser.\r\n        \/\/ Use '\\x26#60;' instead of '<' so that the XML parser\r\n        \/\/ doesn't go ahead and substitute the less-than character. \r\n        code_string = code_string.replace(\/\\x3C\/g, '\\x26#60;');\r\n\r\n        copyright = 'Copyright 2013 The MathWorks, Inc.';\r\n\r\n        w = window.open();\r\n        d = w.document;\r\n        d.write('<pre>\\n');\r\n        d.write(code_string);\r\n\r\n        \/\/ Add copyright line at the bottom if specified.\r\n        if (copyright.length > 0) {\r\n            d.writeln('');\r\n            d.writeln('%%');\r\n            if (copyright.length > 0) {\r\n                d.writeln('% _' + copyright + '_');\r\n            }\r\n        }\r\n\r\n        d.write('<\/pre>\\n');\r\n\r\n        d.title = title + ' (MATLAB code)';\r\n        d.close();\r\n    }   \r\n     --> <\/script><p style=\"text-align: right; font-size: xx-small; font-weight:lighter;   font-style: italic; color: gray\"><br><a href=\"javascript:grabCode_c52d932239354ddabeadec30b05742fe()\"><span style=\"font-size: x-small;        font-style: italic;\">Get \r\n      the MATLAB code <noscript>(requires JavaScript)<\/noscript><\/span><\/a><br><br>\r\n      Published with MATLAB&reg; R2012b<br><\/p><p class=\"footer\"><br>\r\n      Published with MATLAB&reg; R2012b<br><\/p><\/div><!--\r\nc52d932239354ddabeadec30b05742fe ##### SOURCE BEGIN #####\r\n%% Super Bowl Squares\r\n% <https:\/\/blogs.mathworks.com\/community\/2012\/11\/20\/england-football-and-comma-separated-tables\/\r\n% In my last post> I wrote about English football. This time I'm talking\r\n% about the American version. Here in the U.S. it's playoff season for\r\n% professional football, and that means greasy food, beer, big-screen\r\n% televisions, and football squares.\r\n%\r\n% And what are football squares, you may ask? It's a simple mechanism to\r\n% let a crowd of people wager on the outcome of a ballgame. Consider the\r\n% following plot.\r\n\r\na = invhilb(10)<0; \r\n% Why invhilb? See this Cody problem:\r\n%   https:\/\/www.mathworks.com\/matlabcentral\/cody\/problems\/4-make-a-checkerboard-matrix\r\ntick = 0:9;\r\nimagesc(tick,tick,a)\r\ncolormap([1; 0.8]*[1 1 1])\r\nset(gca, ...\r\n    'XAxisLocation','top', ...\r\n    'XTick',tick, ...\r\n    'YTick',tick)\r\naxis square\r\nxlabel('Last Digit of Team A''s Score')\r\nylabel('Last Digit of Team B''s Score')\r\n\r\n%%\r\n% It has 100 small squares in it, each one corresponding to a pair of\r\n% one-digit numbers. These one-digit numbers, in turn, correspond to the\r\n% last digit in the final score of one of the two teams. Before the game,\r\n% everyone buys one or more squares until they've all been sold. Now, if\r\n% the Alligators (team A) go on to defeat the Buckaroos (team B) 17-10,\r\n% then the owner of the square at location (7,0) would be the winner. \r\n%\r\n% As you can imagine, some score pairs are much more likely than others.\r\n% For this reason, in practice the squares are usually sold off at random.\r\n% You don't get to pick which score pair you will receive. \r\n%\r\n% All this sets the scene for a Super Bowl party from a few years ago. The\r\n% Green Bay Packers were playing the Pittsburgh Steelers, and I had acquired\r\n% a square. But not just any square. My square was linked to the score\r\n% pair (2,2).\r\n%\r\n% <<http:\/\/inside-files.mathworks.com\/public\/Ned_Gulley\/images\/football-squares.png>>\r\n%\r\n% This struck me as a rare score pair. But how rare? Being quantitatively\r\n% minded, and armed with my favorite technical computing tool, I went\r\n% looking for data.\r\n%\r\n% A little web searching turned up a site with\r\n% <#game_scores::none\r\n% every single NFL football game played since 1920>, nearly 15,000 games. A savvy\r\n% reader may observe that the game has changed a lot during that interval.\r\n% Nevermind that! Let's do the calculations and see what we get.\r\n\r\n%% Get the Data\r\n% First grab the HTML.\r\n\r\nurl = '#game_scores::none';\r\nhtml = urlread(url);\r\n\r\n%% Regular Expressions to the Rescue!\r\n% By carefully examining the structure of the HTML, we can make a regular\r\n% expression target that will extract the information we need.\r\n\r\ntarget = [ ...\r\n    '<tr  class=\"\">\\s*' ...\r\n    '<td align=\"right\"  csk.*?>.*?<\/td>\\s*' ...\r\n    '<td align=\"right\"  csk.*?>.*?<\/td>\\s*' ...\r\n    '<td align=\"right\" >(\\d+)<\/td>\\s*' ...\r\n    '<td align=\"right\" >(\\d+)<\/td>\\s*' ...\r\n    '<td align=\"right\" >\\d+<\/td>\\s*' ...\r\n    '<td align=\"right\" >\\d+<\/td>\\s*' ...\r\n    '<td align=\"right\"  csk.*?><a href=\".*?\">(\\d+)<\/a><\/td>\\s*' ...\r\n    ];\r\ntk = regexp(html,target,'tokens');\r\n\r\n%% Populate the Results Matrix\r\n% Armed with the textual data from the HTML, we can insert it into a matrix\r\n% with counts for all the possible outcomes.\r\n\r\nscore = zeros(100);\r\noneDigitScore = zeros(10);\r\n\r\nfor i = 1:length(tk)\r\n    winning = str2num(tk{i}{1});\r\n    winningMod10 = mod(winning,10);\r\n    losing = str2num(tk{i}{2});\r\n    losingMod10 = mod(losing,10);\r\n    game_count = str2num(tk{i}{3});\r\n    \r\n    % 100-by-100 score grid with actual final scores\r\n    score(winning+1,losing+1) = game_count;\r\n    \r\n    % 10-by-10 score grid with mod 10 final scores\r\n    oneDigitScore(winningMod10+1,losingMod10+1) = oneDigitScore(winningMod10+1,losingMod10+1) + game_count\/2;\r\n    oneDigitScore(losingMod10+1,winningMod10+1) = oneDigitScore(losingMod10+1,winningMod10+1) + game_count\/2;\r\n    \r\nend\r\n\r\n%% Compute the Probability Matrix\r\n% Calculate percentages based on the total number of games and visualize\r\n% the results.\r\n\r\nprob = oneDigitScore\/sum(oneDigitScore(:))*100;\r\nimagesc(0:9,0:9,prob)\r\ncolormap(summer(64))\r\ncolorbar\r\n\r\nset(gca, ...\r\n    'XAxisLocation','top', ...\r\n    'XTick',tick, ...\r\n    'YTick',tick)\r\naxis square\r\nxlabel('Last Digit of Team A''s Score')\r\nylabel('Last Digit of Team B''s Score')\r\n\r\n\r\n%% \r\n% Just to be safe, let's verify that the sum of the probability matrix is\r\n% 100%.\r\n\r\nfprintf('Sum of all probabilities (percent): %2.1f\\n',sum(prob(:)));\r\n\r\n%% Add Numbers to the Plot\r\n% No surprise: the likeliest outcome is the pair (7,0) or (0,7). What about\r\n% (2,2)? It's looking pretty grim. Let's throw some numbers on the plot to\r\n% find out.\r\n\r\ncolorbar off\r\n\r\n[rows,cols] = size(prob);\r\nfor i = 1:rows\r\n  for j = 1:cols\r\n    text(j-1,i-1,sprintf('%1.2f',prob(i,j)),...\r\n        'FontSize', 8, ...\r\n      'Color','red', ...\r\n      'HorizontalAlignment','center');\r\n  end\r\nend\r\n\r\nset(gca,'XAxisLocation','top')\r\nxlabel('Last Digit of Steelers Score')\r\nylabel('Last Digit of Packers Score')\r\n\r\npatch([2 3 3 2 2]-0.5,[2 2 3 3 2]-0.5,'red', ...\r\n  'FaceColor','none','LineWidth',2,'EdgeColor','yellow')\r\npatch([5 6 6 5 5]-0.5,[1 1 2 2 1]-0.5,'red', ...\r\n  'FaceColor','none','LineWidth',2,'EdgeColor','yellow')\r\n\r\n%%\r\n% Ouch!\r\n\r\n%% The Bottom Line \r\n% All this is a long-winded way of saying that my pick, (2,2),\r\n% is the absolute worst possible choice. Since the merger in 1970,\r\n% there have been _exactly two games_ that ended with (2,2). On December 5,\r\n% 2004, the Buffalo Bills beat the Miami Dolphins 42-32, and on November 4,\r\n% 2012 the Tampa Bay Buccaneers defeated the Oakland Raiders by the same\r\n% score.\r\n%\r\n% Incidentally, the actual winning result for Steelers-Packers Super Bowl,\r\n% (1,5), is also quite rare. Rare as these things go, but still eleven\r\n% times more likely than (2,2). \r\n% \r\n% Not that I'm bitter about it.\r\n\r\n##### SOURCE END ##### c52d932239354ddabeadec30b05742fe\r\n-->","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img decoding=\"async\"  class=\"img-responsive\" src=\"https:\/\/blogs.mathworks.com\/community\/files\/squares_01.png\" onError=\"this.style.display ='none';\" \/><\/div><p>\r\n\r\n\r\nh1 { font-size:18pt; }\r\nh2.titlebg { font-size:13pt; }\r\nh3 { color:#4A4F55; padding:0px; margin:5px 0px 5px; font-family:Arial, Helvetica, sans-serif; font-size:11pt; font-weight:bold;... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/community\/2013\/01\/07\/football-squares-with-matlab\/\">read more >><\/a><\/p>","protected":false},"author":69,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/posts\/1996"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/users\/69"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/comments?post=1996"}],"version-history":[{"count":12,"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/posts\/1996\/revisions"}],"predecessor-version":[{"id":2076,"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/posts\/1996\/revisions\/2076"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/media?parent=1996"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/categories?post=1996"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/tags?post=1996"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}