{"id":5876,"date":"2015-03-06T09:00:58","date_gmt":"2015-03-06T14:00:58","guid":{"rendered":"https:\/\/blogs.mathworks.com\/pick\/?p=5876"},"modified":"2015-03-05T10:27:58","modified_gmt":"2015-03-05T15:27:58","slug":"plot-subfunctions","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/pick\/2015\/03\/06\/plot-subfunctions\/","title":{"rendered":"Plot Subfunctions"},"content":{"rendered":"<div xmlns:mwsh=\"https:\/\/www.mathworks.com\/namespace\/mcode\/v1\/syntaxhighlight.dtd\" class=\"content\">\r\n   <introduction>\r\n      <p>Posted by <b>Richard Ruff<\/b> , March 6, 2015\r\n      <\/p>\r\n      <p><i>Richard is an Application Engineer at MathWorks focused on the Embedded Coder product for code generation, primarily in the\r\n            Aerospace industry.<\/i><\/p>\r\n      <p><a href=\"https:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/1016860-richard-ruff\">Richard's<\/a> pick this week is <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/46070-plot-subfun\">plot_subfun<\/a> by <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/2130826-christopher-pedersen\">Christopher Pedersen<\/a>.\r\n      <\/p>\r\n   <\/introduction>\r\n   <p>My pick this week is the utility function <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/46070-plot-subfun\">plot_subfun<\/a> for visualizing the subroutines in a file via a node map.\r\n   <\/p>\r\n   <p>Have you ever been given a MATLAB file only to spend many hours reading through it to understand the calling structure?  If\r\n      so, this function can save a lot of time by providing a snapshot of the calling structure, thus allowing you to quickly see\r\n      the interaction between the various subroutines. As the saying goes, a picture is worth a thousand words and this function\r\n      gives you the picture from the thousand words or five thousand words or ...\r\n   <\/p>\r\n   <p>The File Exchange submission includes an extensive demo script, 'demo_subfun.m', that provides very detailed examples for\r\n      using plot_subfun.  A basic example is shown here:\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">plot_subfun(<span style=\"color: #A020F0\">'plot_subfun'<\/span>);<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/Richard\/main_FunctionPlotter\/main_FunctionPlotter_01.png\"> <p>There are a number of options that allow the user to customize the results generated by plot_subfun.  These options are:<\/p>\r\n   <div>\r\n      <ul>\r\n         <li><b>-ends<\/b>: <i>hide functions with one parent and no kids<\/i><\/li>\r\n         <li><b>-ext<\/b>: <i>show calls to external functions in a separate list<\/i><\/li>\r\n         <li><b>-hide<\/b>: <i>hide named functions and their children<\/i><\/li>\r\n         <li><b>-kids<\/b>: <i>same as <b>-hide<\/b>, but only hides the children<\/i><\/li>\r\n         <li><b>-list<\/b>: <i>display list of all functions and their calls to command line<\/i><\/li>\r\n         <li><b>-nest<\/b>: <i>hide nested functions<\/i><\/li>\r\n         <li><b>-noplot<\/b>: <i>do not plot the figure<\/i><\/li>\r\n         <li><b>-trim<\/b>: <i>trims the output to just the visible functions<\/i><\/li>\r\n         <li><b>-unhide<\/b>: <i>hidden functions are shown in grey instead<\/i><\/li>\r\n         <li><b>-unused<\/b>: <i>also show functions that are not called<\/i><\/li>\r\n         <li><b>-unusedonly<\/b>: <i>only show functions that are not called<\/i><\/li>\r\n      <\/ul>\r\n   <\/div>\r\n   <p>I find plot_subfun particularly useful when developing custom UIs in MATLAB as I can quickly see what callbacks are being\r\n      used and any utility routines that are shared.  In addition, it can help point out where missing connections are such as needing\r\n      to call a specific routine if the user selects an option such as switching between tabs on a UI and updating the data being\r\n      displayed.\r\n   <\/p>\r\n   <p>While there is an option to list the extenal functions that are called, I would like to see the option to include a set of\r\n      files to analyze in order to see the dependency between the functions in multiple files. For Example, I have two files mainUI.m\r\n      and fillUIPanel.m, I&#8217;d like to see this syntax work:\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">plot_subfun({<span style=\"color: #A020F0\">'mainUI.m'<\/span>, <span style=\"color: #A020F0\">'fillUIPanel.m'<\/span>});<\/pre><h3>Comments<a name=\"5\"><\/a><\/h3>\r\n   <p>Give it a try and let us know what you think <a href=\"https:\/\/blogs.mathworks.com\/pick\/?p=5876#respond\">here<\/a> or leave a <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/46070-plot-subfun#comments\">comment<\/a> for Christopher.\r\n   <\/p><script language=\"JavaScript\">\r\n<!--\r\n\r\n    function grabCode_1f409ba93c0641b9958d15e4615b673b() {\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='1f409ba93c0641b9958d15e4615b673b ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 1f409ba93c0641b9958d15e4615b673b';\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        author = 'Richard Ruff';\r\n        copyright = 'Copyright 2015 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 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');\r\n      \r\n      d.title = title + ' (MATLAB code)';\r\n      d.close();\r\n      }   \r\n      \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_1f409ba93c0641b9958d15e4615b673b()\"><span style=\"font-size: x-small;        font-style: italic;\">Get \r\n            the MATLAB code \r\n            <noscript>(requires JavaScript)<\/noscript><\/span><\/a><br><br>\r\n      Published with MATLAB&reg; R2015a<br><\/p>\r\n<\/div>\r\n<!--\r\n1f409ba93c0641b9958d15e4615b673b ##### SOURCE BEGIN #####\r\n%% plot_subfun\r\n%\r\n% Posted by *Richard Ruff* , March 6, 2015\r\n%\r\n% _Richard is an Application Engineer at MathWorks focused on the Embedded\r\n% Coder product for code generation, primarily in the Aerospace industry._\r\n% \r\n% <https:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/1016860-richard-ruff\r\n% Richard's> pick this week is\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/46070-plot-subfun\r\n% plot_subfun> by\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/2130826-christopher-pedersen\r\n% Christopher Pedersen>.\r\n% \r\n%% Pick\r\n% My pick this week is the utility function\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/46070-plot-subfun\r\n% plot_subfun> for visualizing the subroutines in a file via a node map.\r\n%\r\n% Have you ever been given a MATLAB file only to spend many hours reading\r\n% through it to understand the calling structure?  If so, this function can\r\n% save a lot of time by providing a snapshot of the calling structure, thus\r\n% allowing you to quickly see the interaction between the various\r\n% subroutines. As the saying goes, a picture is worth a thousand words and\r\n% this function gives you the picture from the thousand words or five\r\n% thousand words or ...\r\n%\r\n% The File Exchange submission includes an extensive demo script,\r\n% 'demo_subfun.m', that provides very detailed examples for using\r\n% plot_subfun.  A basic example is shown here:\r\n%\r\nplot_subfun('plot_subfun');\r\n\r\n%%\r\n% There are a number of options that allow the user to customize the\r\n% results generated by plot_subfun.  These options are:\r\n%%\r\n% * *-ends*: _hide functions with one parent and no kids_\r\n% * *-ext*: _show calls to external functions in a separate list_\r\n% * *-hide*: _hide named functions and their children_\r\n% * *-kids*: _same as *-hide*, but only hides the children_\r\n% * *-list*: _display list of all functions and their calls to command line_\r\n% * *-nest*: _hide nested functions_\r\n% * *-noplot*: _do not plot the figure_\r\n% * *-trim*: _trims the output to just the visible functions_\r\n% * *-unhide*: _hidden functions are shown in grey instead_\r\n% * *-unused*: _also show functions that are not called_\r\n% * *-unusedonly*: _only show functions that are not called_\r\n% \r\n%%\r\n% I find plot_subfun particularly useful when developing custom UIs in\r\n% MATLAB as I can quickly see what callbacks are being used and any utility\r\n% routines that are shared.  In addition, it can help point out where\r\n% missing connections are such as needing to call a specific routine if the\r\n% user selects an option such as switching between tabs on a UI and\r\n% updating the data being displayed.\r\n%\r\n% While there is an option to list the extenal functions that are called, I\r\n% would like to see the option to include a set of files to analyze in\r\n% order to see the dependency between the functions in multiple files.\r\n% For Example, I have two files mainUI.m and fillUIPanel.m, I\u00e2\u20ac\u2122d like to see\r\n% this syntax work:\r\n% \r\n%   plot_subfun({'mainUI.m', 'fillUIPanel.m'});\r\n% \r\n\r\n%% Comments\r\n% \r\n% Give it a try and let us know what you think\r\n% <https:\/\/blogs.mathworks.com\/pick\/?p=5876#respond here> or leave a\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/46070-plot-subfun#comments\r\n% comment> for Christopher.\r\n%\r\n \r\n\r\n##### SOURCE END ##### 1f409ba93c0641b9958d15e4615b673b\r\n-->","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img decoding=\"async\"  class=\"img-responsive\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/Richard\/main_FunctionPlotter\/main_FunctionPlotter_01.png\" onError=\"this.style.display ='none';\" \/><\/div><p>\r\n   \r\n      Posted by Richard Ruff , March 6, 2015\r\n      \r\n      Richard is an Application Engineer at MathWorks focused on the Embedded Coder product for code generation, primarily in the\r\n  ... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/pick\/2015\/03\/06\/plot-subfunctions\/\">read more >><\/a><\/p>","protected":false},"author":36,"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\/5876"}],"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\/36"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/comments?post=5876"}],"version-history":[{"count":3,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/5876\/revisions"}],"predecessor-version":[{"id":5881,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/5876\/revisions\/5881"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media?parent=5876"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/categories?post=5876"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/tags?post=5876"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}