{"id":3776,"date":"2016-06-16T15:08:16","date_gmt":"2016-06-16T19:08:16","guid":{"rendered":"https:\/\/blogs.mathworks.com\/community\/?p=3776"},"modified":"2016-06-16T15:08:16","modified_gmt":"2016-06-16T19:08:16","slug":"soccer-passing-networks","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/community\/2016\/06\/16\/soccer-passing-networks\/","title":{"rendered":"Soccer Passing Networks"},"content":{"rendered":"<p>I saw another fun MATLAB-related tweet go by, this time about soccer rather than doughnuts. The Euro 2016 tournament is going on right now, and <a href=\"https:\/\/twitter.com\/ZPedro10\">Jos\u00e9 Pedro Silva<\/a> tweeted a cool MATLAB-generated visualization about passing between the players. This is showing the passing in the Portugal-Iceland match.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" width=\"580\" height=\"544\" src=\"https:\/\/blogs.mathworks.com\/community\/files\/passing_network_1.png\" alt=\"passing_network_1\" class=\"alignnone size-full wp-image-3778\" \/><\/p>\n<p><a href=\"https:\/\/twitter.com\/ZPedro10\/status\/743115988581896192\">https:\/\/twitter.com\/ZPedro10\/status\/743115988581896192<\/a><\/p>\n<p>The game resulted in a 1-1 draw, but just looking at the passing! The line weights show how many more touches Portugal had than Iceland. And indeed, Iceland only managed 28% of possession.<\/p>\n<h3>Digraphs in MATLAB<\/h3>\n<p>I don&#8217;t have access to the fancy code that generated that plot, but I can use this opportunity to show off MATLAB&#8217;s graphing capability. Let&#8217;s make up some totally random names and passing statistics for a five-man soccer team.<\/p>\n<pre id=\"matlabcode\" class=\"matlab-code\" style=\"background-color: #f7f7f7; font-family: monospace; font-weight: normal; padding-top: 5px; padding-bottom: 5px; line-height: 150%; border: 1px solid #E9E9E9;\">names = { <span style=\"color: #0000ff;\">...<\/span>\r\n            <span style=\"color: #a020f0;\">'Lionel Alpha'<\/span>, \r\n            <span style=\"color: #a020f0;\">'Cristiano Bravo'<\/span>,\r\n            <span style=\"color: #a020f0;\">'Gareth Charlie'<\/span>,\r\n            <span style=\"color: #a020f0;\">'Zlatan Delta'<\/span>,\r\n            <span style=\"color: #a020f0;\">'Sergio Echo'<\/span>};\r\n<\/pre>\n<p>Now we can show the edges of the graph: who passed the ball (source), who received it (target) and how many passes they made (numPasses). The number of passes will be assigned to the weight of each edge. So we can see that Alpha passed to Bravo exactly once during the match. Bravo never returned the favor.<\/p>\n<pre id=\"matlabcode\" class=\"matlab-code\" style=\"background-color: #f7f7f7; font-family: monospace; font-weight: normal; padding-top: 5px; padding-bottom: 5px; line-height: 150%; border: 1px solid #E9E9E9;\">        source    = [1 1 1 2 3 3 3 3 4 4 4 5 5 5 5];\r\n        target    = [2 4 5 4 1 2 4 5 2 3 5 1 2 3 4];\r\n        numPasses = [1 2 1 1 5 2 2 3 2 2 1 4 6 4 8];\r\n        weight = numPasses;\r\n        G = digraph(source,target,weight,names);\r\n        G.Nodes\r\n<\/pre>\n<pre class=\"output\" style=\"font-family: monospace; border: none; background-color: white; color: rgba(64, 64, 64, 1);\">ans = \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Name\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \r\n\u00a0\u00a0\u00a0\u00a0_________________\r\n\r\n\u00a0\u00a0\u00a0\u00a0'Lionel Alpha'\u00a0\u00a0 \r\n\u00a0\u00a0\u00a0\u00a0'Cristiano Bravo'\r\n\u00a0\u00a0\u00a0\u00a0'Gareth Charlie' \r\n\u00a0\u00a0\u00a0\u00a0'Zlatan Delta'\u00a0\u00a0 \r\n\u00a0\u00a0\u00a0\u00a0'Sergio Echo'\u00a0\u00a0\u00a0\u00a0\r\n\r\n\r\n<\/pre>\n<pre id=\"matlabcode\" class=\"matlab-code\" style=\"background-color: #f7f7f7; font-family: monospace; font-weight: normal; padding-top: 5px; padding-bottom: 5px; line-height: 150%; border: 1px solid #E9E9E9;\">        G.Edges\r\n<\/pre>\n<pre class=\"output\" style=\"font-family: monospace; border: none; background-color: white; color: rgba(64, 64, 64, 1);\">ans = \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 EndNodes\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0\u00a0Weight\r\n\u00a0\u00a0\u00a0\u00a0______________________________________\u00a0\u00a0\u00a0\u00a0______\r\n\r\n\u00a0\u00a0\u00a0\u00a0'Lionel Alpha'\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 'Cristiano Bravo'\u00a0\u00a0\u00a0\u00a01\u00a0\u00a0\u00a0\u00a0 \r\n\u00a0\u00a0\u00a0\u00a0'Lionel Alpha'\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 'Zlatan Delta'\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 2\u00a0\u00a0\u00a0\u00a0 \r\n\u00a0\u00a0\u00a0\u00a0'Lionel Alpha'\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 'Sergio Echo'\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a01\u00a0\u00a0\u00a0\u00a0 \r\n\u00a0\u00a0\u00a0\u00a0'Cristiano Bravo'\u00a0\u00a0\u00a0\u00a0'Zlatan Delta'\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 1\u00a0\u00a0\u00a0\u00a0 \r\n\u00a0\u00a0\u00a0\u00a0'Gareth Charlie'\u00a0\u00a0\u00a0\u00a0 'Lionel Alpha'\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 5\u00a0\u00a0\u00a0\u00a0 \r\n\u00a0\u00a0\u00a0\u00a0'Gareth Charlie'\u00a0\u00a0\u00a0\u00a0 'Cristiano Bravo'\u00a0\u00a0\u00a0\u00a02\u00a0\u00a0\u00a0\u00a0 \r\n\u00a0\u00a0\u00a0\u00a0'Gareth Charlie'\u00a0\u00a0\u00a0\u00a0 'Zlatan Delta'\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 2\u00a0\u00a0\u00a0\u00a0 \r\n\u00a0\u00a0\u00a0\u00a0'Gareth Charlie'\u00a0\u00a0\u00a0\u00a0 'Sergio Echo'\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a03\u00a0\u00a0\u00a0\u00a0 \r\n\u00a0\u00a0\u00a0\u00a0'Zlatan Delta'\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 'Cristiano Bravo'\u00a0\u00a0\u00a0\u00a02\u00a0\u00a0\u00a0\u00a0 \r\n\u00a0\u00a0\u00a0\u00a0'Zlatan Delta'\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 'Gareth Charlie'\u00a0\u00a0\u00a0\u00a0 2\u00a0\u00a0\u00a0\u00a0 \r\n\u00a0\u00a0\u00a0\u00a0'Zlatan Delta'\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 'Sergio Echo'\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a01\u00a0\u00a0\u00a0\u00a0 \r\n\u00a0\u00a0\u00a0\u00a0'Sergio Echo'\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0'Lionel Alpha'\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 4\u00a0\u00a0\u00a0\u00a0 \r\n\u00a0\u00a0\u00a0\u00a0'Sergio Echo'\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0'Cristiano Bravo'\u00a0\u00a0\u00a0\u00a06\u00a0\u00a0\u00a0\u00a0 \r\n\u00a0\u00a0\u00a0\u00a0'Sergio Echo'\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0'Gareth Charlie'\u00a0\u00a0\u00a0\u00a0 4\u00a0\u00a0\u00a0\u00a0 \r\n\u00a0\u00a0\u00a0\u00a0'Sergio Echo'\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0'Zlatan Delta'\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 8\u00a0\u00a0\u00a0\u00a0 \r\n\r\n\r\n<\/pre>\n<p>Look how easy it is to make a simple directed graph. Sergio Echo is clearly a passing machine. For Bravo, it was far better to receive than to give.<\/p>\n<pre id=\"matlabcode\" class=\"matlab-code\" style=\"background-color: #f7f7f7; font-family: monospace; font-weight: normal; padding-top: 5px; padding-bottom: 5px; line-height: 150%; border: 1px solid #E9E9E9;\">        plot(G,<span style=\"color: #a020f0;\">'Layout'<\/span>,<span style=\"color: #a020f0;\">'circle'<\/span>,<span style=\"color: #a020f0;\">'LineWidth'<\/span>,G.Edges.Weight,<span style=\"color: #a020f0;\">'ArrowSize'<\/span>,15)\r\n        axis <span style=\"color: #a020f0;\">off<\/span>\r\n<\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" width=\"560\" height=\"420\" src=\"https:\/\/blogs.mathworks.com\/community\/files\/passing_network_2.png\" alt=\"passing_network_2\" class=\"alignnone size-full wp-image-3777\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img decoding=\"async\"  class=\"img-responsive\" src=\"https:\/\/blogs.mathworks.com\/community\/files\/passing_network_1.png\" onError=\"this.style.display ='none';\" \/><\/div>\n<p>I saw another fun MATLAB-related tweet go by, this time about soccer rather than doughnuts. The Euro 2016 tournament is going on right now, and Jos\u00e9 Pedro Silva tweeted a cool MATLAB-generated&#8230; <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/community\/2016\/06\/16\/soccer-passing-networks\/\">read more >><\/a><\/p>\n","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\/3776"}],"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=3776"}],"version-history":[{"count":2,"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/posts\/3776\/revisions"}],"predecessor-version":[{"id":3780,"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/posts\/3776\/revisions\/3780"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/media?parent=3776"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/categories?post=3776"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/tags?post=3776"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}