{"id":10155,"date":"2018-09-21T09:00:18","date_gmt":"2018-09-21T13:00:18","guid":{"rendered":"https:\/\/blogs.mathworks.com\/pick\/?p=10155"},"modified":"2018-09-18T11:22:16","modified_gmt":"2018-09-18T15:22:16","slug":"r2018b-features","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/pick\/2018\/09\/21\/r2018b-features\/","title":{"rendered":"R2018b Features"},"content":{"rendered":"<div xmlns:mwsh=\"http:\/\/www.mathworks.com\/namespace\/mcode\/v1\/syntaxhighlight.dtd\" class=\"content\">\n   <introduction><\/p>\n<p><a href=\"http:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/3208495\">Sean<\/a>&#8216;s pick this week is my biannual review of former picks that are now part of the product.  <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2018b\/matlab\/release-notes.html\">R2018b<\/a> shipped last week bringing with it a few new things I really like.\n      <\/p>\n<p>   <\/introduction><\/p>\n<h3>Contents<\/h3>\n<div>\n<ul>\n<li><a href=\"#1\">Subplot Title (!)<\/a><\/li>\n<li><a href=\"#2\">Draw a Line<\/a><\/li>\n<li><a href=\"#3\">Convert App Designer App to Class<\/a><\/li>\n<li><a href=\"#4\">STL Read and Write<\/a><\/li>\n<li><a href=\"#5\">Other<\/a><\/li>\n<li><a href=\"#7\">Comments<\/a><\/li>\n<\/ul><\/div>\n<h3>Subplot Title (!)<a name=\"1\"><\/a><\/h3>\n<p>Have you ever wanted to add a title above your subplots?<\/p>\n<p>There has been a function called <tt>suptitle<\/tt> in the demos section of the Bioinformatics Toolbox for quite some time.  While not formally documented, it provided a convenient way to add a &#8220;super title&#8221; to a plot, if you have that toolbox.  Numerous File Exchange entries and pick of the weeks have filled this gap for over 20 years.  In R2018b, there is <i>finally(!)<\/i> <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/sgtitle.html\"><tt>sgtitle<\/tt><\/a>.  I&#8217;ll showcase it using another new function called <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/stackedplot.html\"><tt>stackedplot<\/tt><\/a> for plotting many responses to one independent variable or for plotting tables\/timetables.\n   <\/p>\n<pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">T = readtable(<span style=\"color: #A020F0\">'patients.dat'<\/span>);\r\nsubplot(1, 2, 1)\r\nstackedplot(T);\r\ntitle(<span style=\"color: #A020F0\">'Patients'<\/span>)\r\nsubplot(1, 2, 2)\r\nstackedplot(flip(T));\r\ntitle(<span style=\"color: #A020F0\">'Impatients'<\/span>)\r\nsgtitle(<span style=\"color: #A020F0\">'Patiently Waited'<\/span>)\r\ndrawnow<\/pre>\n<p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/pick\/files\/main18b_01.png\"> <\/p>\n<h3>Draw a Line<a name=\"2\"><\/a><\/h3>\n<p>The File Exchange entries for vertical and horizontal lines have also been around for a long time.  R2018b introduces <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/xline.html\"><tt>xline<\/tt><\/a> and <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/yline.html\"><tt>yline<\/tt><\/a> for drawing constant lines on your plots that rescale with the axes zoom\/pan.\n   <\/p>\n<pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">t = dateshift(datetime(<span style=\"color: #A020F0\">'yesterday'<\/span>),<span style=\"color: #A020F0\">'start'<\/span>,<span style=\"color: #A020F0\">'day'<\/span>):hours(1):dateshift(datetime(<span style=\"color: #A020F0\">'tomorrow'<\/span>),<span style=\"color: #A020F0\">'end'<\/span>,<span style=\"color: #A020F0\">'day'<\/span>);\r\ny = cumsum(rand(size(t)));\r\n\r\nfigure\r\nplot(t, y)\r\nxline(datetime(<span style=\"color: #A020F0\">'now'<\/span>), <span style=\"color: #A020F0\">'Label'<\/span>, <span style=\"color: #A020F0\">\"Now\"<\/span>);\r\nyline(20, <span style=\"color: #A020F0\">'--'<\/span>, <span style=\"color: #A020F0\">\"20\"<\/span>);<\/pre>\n<p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/pick\/files\/main18b_02.png\"> <\/p>\n<h3>Convert App Designer App to Class<a name=\"3\"><\/a><\/h3>\n<p>There is a well rated File Exchange entry called <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/56237\"><tt>mlapp2classdef<\/tt><\/a> which parses the undocumented format to convert an app designer app to a standalone class definition file.  This workflow is nice for working with source control systems or when you want to use the regular editor.  That capability is now part of R2018b&#8217;s app designer and can be accessed from <b>Save -&gt; Export to *.m File<\/b>.  <b>Note<\/b> it does not allow &#8220;round-tripping&#8221; so you cannot pull a modified class file back into app designer; though you could copy parts of the code back into the app designer editor.\n   <\/p>\n<h3>STL Read and Write<a name=\"4\"><\/a><\/h3>\n<p>There are numerous readers and writers on the File Exchange (and in MathWorks&#8217; Toolboxes) for Stereolithography (STL) files.  There are now functions <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/stlread.html\"><tt>stlread<\/tt><\/a> and <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/stlwrite.html\"><tt>stlwrite<\/tt><\/a> in base MATLAB for this.\n   <\/p>\n<pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">xy = rand(10, 2);\r\ndt = delaunayTriangulation(xy);\r\nfilename = tempname + <span style=\"color: #A020F0\">\".stl\"<\/span>;\r\ndeleter = onCleanup(@()delete(filename));\r\nstlwrite(dt, filename);\r\n\r\nfigure\r\nsubplot(1, 2, 1);\r\ntriplot(dt);\r\ntitle(<span style=\"color: #A020F0\">\"Original Delaunay Triangulation\"<\/span>);\r\nsubplot(1, 2, 2);\r\ntriplot(stlread(filename));\r\ntitle(<span style=\"color: #A020F0\">\"Written and Read Triangulation\"<\/span>);\r\nsgtitle(<span style=\"color: #A020F0\">\"Triangulations Should Match\"<\/span>)<\/pre>\n<p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/pick\/files\/main18b_03.png\"> <\/p>\n<h3>Other<a name=\"5\"><\/a><\/h3>\n<p>Of course there are many other nice things as well.  One that I like is that most functions now support strings.  So if I want to open that STL file for 3D printing outside of MATLAB, I can without having to convert to char or cellstr.\n   <\/p>\n<pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">winopen(filename)<\/pre>\n<p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/pick\/files\/stlview.png\"> <\/p>\n<h3>Comments<a name=\"7\"><\/a><\/h3>\n<p>Give R2018b a try and let us know what you think about these or any other <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2018b\/matlab\/release-notes.html\">features<\/a> <a href=\"http:\/\/blogs.mathworks.com\/pick\/?p=10155#respond\">here<\/a>.\n   <\/p>\n<p><script language=\"JavaScript\">\n<!--\n\n    function grabCode_14094e898e8246aea51844de623552d0() {\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='14094e898e8246aea51844de623552d0 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 14094e898e8246aea51844de623552d0';\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 2018 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_14094e898e8246aea51844de623552d0()\"><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; R2018b<\/p>\n<\/div>\n<p><!--\n14094e898e8246aea51844de623552d0 ##### SOURCE BEGIN #####\n%% R2018b Features\n%\n% <http:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/3208495 Sean>'s\n% pick this week is my biannual review of former picks that are now part\n% of the product.  <https:\/\/www.mathworks.com\/help\/releases\/R2018b\/matlab\/release-notes.html R2018b> shipped last week bringing with it a few new\n% things I really like.  \n\n%% Subplot Title (!)\n%\n% Have you ever wanted to add a title above your subplots?\n%\n% There has been a function called |suptitle| in the demos section of the\n% Bioinformatics Toolbox for quite some time.  While not formally\n% documented, it provided a convenient way to add a \"super title\" to a\n% plot, if you have that toolbox.  Numerous File Exchange entries and pick\n% of the weeks have filled this gap for over 20 years.  In R2018b, there is\n% _finally(!)_ <https:\/\/www.mathworks.com\/help\/matlab\/ref\/sgtitle.html\n% |sgtitle|>.  I'll showcase it using another new function called\n% <https:\/\/www.mathworks.com\/help\/matlab\/ref\/stackedplot.html\n% |stackedplot|> for plotting many responses to one independent variable or\n% for plotting tables\/timetables.\n\nT = readtable('patients.dat');\nsubplot(1, 2, 1)\nstackedplot(T);\ntitle('Patients')\nsubplot(1, 2, 2)\nstackedplot(flip(T));\ntitle('Impatients')\nsgtitle('Patiently Waited')\ndrawnow\n\n%% Draw a Line\n%\n% The File Exchange entries for vertical and horizontal lines have also\n% been around for a long time.  R2018b introduces\n% <https:\/\/www.mathworks.com\/help\/matlab\/ref\/xline.html |xline|> and\n% <https:\/\/www.mathworks.com\/help\/matlab\/ref\/yline.html |yline|> for\n% drawing constant lines on your plots that rescale with the axes zoom\/pan.\n%\n\nt = dateshift(datetime('yesterday'),'start','day'):hours(1):dateshift(datetime('tomorrow'),'end','day');\ny = cumsum(rand(size(t)));\n\nfigure\nplot(t, y)\nxline(datetime('now'), 'Label', \"Now\");\nyline(20, 'REPLACE_WITH_DASH_DASH', \"20\");\n\n%% Convert App Designer App to Class\n%\n% There is a well rated File Exchange entry called\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/56237\n% |mlapp2classdef|> which parses the undocumented format to convert an app\n% designer app to a standalone class definition file.  This workflow is\n% nice for working with source control systems or when you want to use the\n% regular editor.  That capability is now part of R2018b's app designer and\n% can be accessed from *Save -> Export to *.m File*.  *Note* it does not\n% allow \"round-tripping\" so you cannot pull a modified class file back into\n% app designer; though you could copy parts of the code back into the app\n% designer editor.\n\n%% STL Read and Write\n%\n% There are numerous readers and writers on the File Exchange (and in\n% MathWorks' Toolboxes) for Stereolithography (STL) files.  There are now\n% functions <https:\/\/www.mathworks.com\/help\/matlab\/ref\/stlread.html\n% |stlread|> and <https:\/\/www.mathworks.com\/help\/matlab\/ref\/stlwrite.html\n% |stlwrite|> in base MATLAB for this.\n\nxy = rand(10, 2);\ndt = delaunayTriangulation(xy);\nfilename = tempname + \".stl\";\ndeleter = onCleanup(@()delete(filename));\nstlwrite(dt, filename);\n\nfigure\nsubplot(1, 2, 1);\ntriplot(dt);\ntitle(\"Original Delaunay Triangulation\");\nsubplot(1, 2, 2);\ntriplot(stlread(filename));\ntitle(\"Written and Read Triangulation\");\nsgtitle(\"Triangulations Should Match\")\n\n\n%% Other\n% \n% Of course there are many other nice things as well.  One that I like is\n% that most functions now support strings.  So if I want to open that STL\n% file outside of MATLAB, I can without having to convert to char or\n% cellstr.\n\nwinopen(filename)\n\n%%\n%\n% <<stlview.png>>\n\n%% Comments\n% \n% Give R2018b a try and let us know what you think about these or any other\n% <https:\/\/www.mathworks.com\/help\/releases\/R2018b\/matlab\/release-notes.html\n% features> <http:\/\/blogs.mathworks.com\/pick\/?p=10155#respond here>.\n%\n##### SOURCE END ##### 14094e898e8246aea51844de623552d0\n--><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img src=\"https:\/\/blogs.mathworks.com\/pick\/files\/main18b_01.png\" class=\"img-responsive attachment-post-thumbnail size-post-thumbnail wp-post-image\" alt=\"\" decoding=\"async\" loading=\"lazy\" \/><\/div>\n<p>Sean&#8216;s pick this week is my biannual review of former picks that are now part of the product.  R2018b shipped last week bringing with it a few new things I really like.<\/p>\n<p>  &#8230; <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/pick\/2018\/09\/21\/r2018b-features\/\">read more >><\/a><\/p>\n","protected":false},"author":87,"featured_media":10165,"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\/10155"}],"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=10155"}],"version-history":[{"count":5,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/10155\/revisions"}],"predecessor-version":[{"id":10179,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/10155\/revisions\/10179"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media\/10165"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media?parent=10155"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/categories?post=10155"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/tags?post=10155"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}