{"id":9220,"date":"2017-12-22T09:00:21","date_gmt":"2017-12-22T14:00:21","guid":{"rendered":"https:\/\/blogs.mathworks.com\/pick\/?p=9220"},"modified":"2017-12-26T10:36:43","modified_gmt":"2017-12-26T15:36:43","slug":"star-wars-api-reader","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/pick\/2017\/12\/22\/star-wars-api-reader\/","title":{"rendered":"Star Wars API Reader"},"content":{"rendered":"<div xmlns:mwsh=\"https:\/\/www.mathworks.com\/namespace\/mcode\/v1\/syntaxhighlight.dtd\" class=\"content\">\n   <introduction><\/p>\n<p><a href=\"https:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/3208495\">Sean<\/a>&#8216;s pick this week is <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/65423-star-wars-api-reader\">Star Wars API Reader<\/a> by <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/3968667\">Heather Gorr<\/a>.\n      <\/p>\n<p>   <\/introduction><\/p>\n<p>What is the average height of an <a href=\"https:\/\/en.wikipedia.org\/wiki\/Ewok\">Ewok<\/a>?\n   <\/p>\n<pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">allspecies = swapiread(<span style=\"color: #A020F0\">'species'<\/span>);\r\nallspecies(allspecies.name == <span style=\"color: #A020F0\">\"Ewok\"<\/span>, <span style=\"color: #A020F0\">'average_height'<\/span>)<\/pre>\n<pre style=\"font-style:oblique\">ans =\r\n  table\r\n    average_height\r\n    ______________\r\n         100      \r\n<\/pre>\n<p>Apparently, they also speak Ewokese!<\/p>\n<p>Do they have names?<\/p>\n<pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">allbeings = swapiread(<span style=\"color: #A020F0\">'people'<\/span>);\r\nallbeings.name(allbeings.species == <span style=\"color: #A020F0\">\"Ewok\"<\/span>)<\/pre>\n<pre style=\"font-style:oblique\">ans = \r\n    \"Wicket Systri Warrick\"\r\n<\/pre>\n<p>Apparently, there&#8217;s only one listed.  That&#8217;s sad.<\/p>\n<p>Heather&#8217;s Star Wars API reader makes it easy to answer questions like these and many others immediately available from the<br \/>\n      MATLAB command line. Now you don&#8217;t even need to look up or feign interest in order to answer that question your Star Wars<br \/>\n      crazed colleague couldn&#8217;t figure out about whatever the third film was.\n   <\/p>\n<pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">films = swapiread(<span style=\"color: #A020F0\">'films'<\/span>);\r\nfilms(films.episode_id==3, <span style=\"color: #A020F0\">'title'<\/span>)\r\nfilms{films.episode_id==3, <span style=\"color: #A020F0\">'opening_crawl'<\/span>}<\/pre>\n<pre style=\"font-style:oblique\">ans =\r\n  table\r\n            title        \r\n    _____________________\r\n    \"Revenge of the Sith\"\r\nans = \r\n    \"War! The Republic is crumbling\r\n     under attacks by the ruthless\r\n     Sith Lord, Count Dooku.\r\n     There are heroes on both sides.\r\n     Evil is everywhere.\r\n     \r\n     In a stunning move, the\r\n     fiendish droid leader, General\r\n     Grievous, has swept into the\r\n     Republic capital and kidnapped\r\n     Chancellor Palpatine, leader of\r\n     the Galactic Senate.\r\n     \r\n     As the Separatist Droid Army\r\n     attempts to flee the besieged\r\n     capital with their valuable\r\n     hostage, two Jedi Knights lead a\r\n     desperate mission to rescue the\r\n     captive Chancellor....\"\r\n<\/pre>\n<h3>Comments<a name=\"4\"><\/a><\/h3>\n<p>Give it a try and let us know what you think <a href=\"https:\/\/blogs.mathworks.com\/pick\/?p=9220#respond\">here<\/a> or leave a <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/65423-star-wars-api-reader#comments\">comment<\/a> for Heather.\n   <\/p>\n<p><script language=\"JavaScript\">\n<!--\n\n    function grabCode_7568aa90a82642769c0451fd819d0f05() {\n        \/\/ Remember the title so we can use it in the new page\n        title = document.title;\n\n        \/\/ Break up these strings so that their presence\n        \/\/ in the Javascript doesn't mess up the search for\n        \/\/ the MATLAB code.\n        t1='7568aa90a82642769c0451fd819d0f05 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 7568aa90a82642769c0451fd819d0f05';\n    \n        b=document.getElementsByTagName('body')[0];\n        i1=b.innerHTML.indexOf(t1)+t1.length;\n        i2=b.innerHTML.indexOf(t2);\n \n        code_string = b.innerHTML.substring(i1, i2);\n        code_string = code_string.replace(\/REPLACE_WITH_DASH_DASH\/g,'--');\n\n        \/\/ Use \/x3C\/g instead of the less-than character to avoid errors \n        \/\/ in the XML parser.\n        \/\/ Use '\\x26#60;' instead of '<' so that the XML parser\n        \/\/ doesn't go ahead and substitute the less-than character. \n        code_string = code_string.replace(\/\\x3C\/g, '\\x26#60;');\n\n        author = 'Sean de Wolski';\n        copyright = 'Copyright 2017 The MathWorks, Inc.';\n\n        w = window.open();\n        d = w.document;\n        d.write('\n\n<pre>\\n');\r\n        d.write(code_string);\r\n\r\n        \/\/ Add author and copyright lines at the bottom if specified.\r\n        if ((author.length > 0) || (copyright.length > 0)) {\r\n            d.writeln('');\r\n            d.writeln('%%');\r\n            if (author.length > 0) {\r\n                d.writeln('% _' + author + '_');\r\n            }\r\n            if (copyright.length > 0) {\r\n                d.writeln('% _' + copyright + '_');\r\n            }\r\n        }\r\n\r\n        d.write('<\/pre>\n\n\\n');\n      \n      d.title = title + ' (MATLAB code)';\n      d.close();\n      }   \n      \n-->\n<\/script><\/p>\n<p style=\"text-align: right; font-size: xx-small; font-weight:lighter;   font-style: italic; color: gray\"><a href=\"javascript:grabCode_7568aa90a82642769c0451fd819d0f05()\"><span style=\"font-size: x-small;        font-style: italic;\">Get<br \/>\n            the MATLAB code<br \/>\n            <noscript>(requires JavaScript)<\/noscript><\/span><\/a><\/p>\n<p>      Published with MATLAB&reg; R2018a<\/p>\n<\/div>\n<p><!--\n7568aa90a82642769c0451fd819d0f05 ##### SOURCE BEGIN #####\n%% Star Wars API Reader\n%\n% <https:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/3208495 Sean>'s pick this week is\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/65423-star-wars-api-reader Star Wars API Reader> by\n% <https:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/3968667 Heather Gorr>.\n% \n\n%% \n% What is the average height of an <https:\/\/en.wikipedia.org\/wiki\/Ewok Ewok>?\n\nallspecies = swapiread('species');\nallspecies(allspecies.name == \"Ewok\", 'average_height')\n\n%%\n% Apparently, they also speak Ewokese!\n%\n% Do they have names?\n\nallbeings = swapiread('people');\nallbeings.name(allbeings.species == \"Ewok\")\n\n%%\n% Apparently, there's only one listed.  That's sad.\n%\n% Heather's Star Wars API reader makes it easy to answer questions like\n% these and many others immediately available from the MATLAB command line.\n% Now you don't even need to look up or feign interest in order to answer\n% that question your Star Wars crazed colleague couldn't figure out about\n% whatever the third film was.\n\nfilms = swapiread('films');\nfilms(films.episode_id==3, 'title')\nfilms{films.episode_id==3, 'opening_crawl'}\n\n%% Comments\n% \n% Give it a try and let us know what you think\n% <https:\/\/blogs.mathworks.com\/pick\/?p=9220#respond here> or leave a\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/65423-star-wars-api-reader#comments\n% comment> for Heather.\n%\n \n\n##### SOURCE END ##### 7568aa90a82642769c0451fd819d0f05\n--><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sean&#8216;s pick this week is Star Wars API Reader by Heather Gorr.<\/p>\n<p>What is the average height of an Ewok?<\/p>\n<p>allspecies = swapiread(&#8216;species&#8217;);<br \/>\nallspecies(allspecies.name ==&#8230; <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/pick\/2017\/12\/22\/star-wars-api-reader\/\">read more >><\/a><\/p>\n","protected":false},"author":87,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[16],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/9220"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/users\/87"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/comments?post=9220"}],"version-history":[{"count":2,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/9220\/revisions"}],"predecessor-version":[{"id":9224,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/9220\/revisions\/9224"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media?parent=9220"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/categories?post=9220"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/tags?post=9220"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}