[4] | 1 | <html xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd"> |
---|
| 2 | <head> |
---|
| 3 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
---|
| 4 | |
---|
| 5 | <!-- |
---|
| 6 | This HTML is auto-generated from an M-file. |
---|
| 7 | To make changes, update the M-file and republish this document. |
---|
| 8 | --> |
---|
| 9 | <title>test_subfuns</title> |
---|
| 10 | <meta name="generator" content="MATLAB 7.0"> |
---|
| 11 | <meta name="date" content="2004-07-26"> |
---|
| 12 | <meta name="m-file" content="test_subfuns"><style> |
---|
| 13 | body { |
---|
| 14 | background-color: white; |
---|
| 15 | margin:10px; |
---|
| 16 | } |
---|
| 17 | h1 { |
---|
| 18 | color: #990000; |
---|
| 19 | font-size: x-large; |
---|
| 20 | } |
---|
| 21 | h2 { |
---|
| 22 | color: #990000; |
---|
| 23 | font-size: medium; |
---|
| 24 | } |
---|
| 25 | p.footer { |
---|
| 26 | text-align: right; |
---|
| 27 | font-size: xx-small; |
---|
| 28 | font-weight: lighter; |
---|
| 29 | font-style: italic; |
---|
| 30 | color: gray; |
---|
| 31 | } |
---|
| 32 | |
---|
| 33 | pre.codeinput { |
---|
| 34 | margin-left: 30px; |
---|
| 35 | } |
---|
| 36 | |
---|
| 37 | span.keyword {color: #0000FF} |
---|
| 38 | span.comment {color: #228B22} |
---|
| 39 | span.string {color: #A020F0} |
---|
| 40 | span.untermstring {color: #B20000} |
---|
| 41 | span.syscmd {color: #B28C00} |
---|
| 42 | |
---|
| 43 | pre.showbuttons { |
---|
| 44 | margin-left: 30px; |
---|
| 45 | border: solid black 2px; |
---|
| 46 | padding: 4px; |
---|
| 47 | background: #EBEFF3; |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | pre.codeoutput { |
---|
| 51 | color: gray; |
---|
| 52 | font-style: italic; |
---|
| 53 | } |
---|
| 54 | pre.error { |
---|
| 55 | color: red; |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | /* Make the text shrink to fit narrow windows, but not stretch too far in |
---|
| 59 | wide windows. On Gecko-based browsers, the shrink-to-fit doesn't work. */ |
---|
| 60 | p,h1,h2,div { |
---|
| 61 | /* for MATLAB's browser */ |
---|
| 62 | width: 600px; |
---|
| 63 | /* for Mozilla, but the "width" tag overrides it anyway */ |
---|
| 64 | max-width: 600px; |
---|
| 65 | /* for IE */ |
---|
| 66 | width:expression(document.body.clientWidth > 620 ? "600px": "auto" ); |
---|
| 67 | } |
---|
| 68 | |
---|
| 69 | </style></head> |
---|
| 70 | <body> |
---|
| 71 | <h1></h1> |
---|
| 72 | <introduction> |
---|
| 73 | <p>Introducing <tt>SubFuns</tt>, a command-line utility to list all <tt>function</tt> declarations within a specified m-file. |
---|
| 74 | </p> |
---|
| 75 | </introduction> |
---|
| 76 | <h2>Contents</h2> |
---|
| 77 | <div> |
---|
| 78 | <ul> |
---|
| 79 | <li><a href="#1">MATLAB functions</a></li> |
---|
| 80 | <li><a href="#2">Different function declarations</a></li> |
---|
| 81 | <li><a href="#3">Problem: How many functions inside an m-file?</a></li> |
---|
| 82 | <li><a href="#4">Solution: custom command-line utility</a></li> |
---|
| 83 | <li><a href="#5">Example</a></li> |
---|
| 84 | </ul> |
---|
| 85 | </div> |
---|
| 86 | <h2>MATLAB functions<a name="1"></a></h2> |
---|
| 87 | <p>Functions are an integral part of MATLAB. They provide higher levels of functionality and abstraction. For example, the standard |
---|
| 88 | deviation of a matrix is the square root of the variance, where the variance is the sum of the squares of the elements divided |
---|
| 89 | by the total number of elements. So, in MATLAB the <tt>std</tt> function calls the <tt>var</tt> function, which in turn calls the <tt>sum</tt> function. |
---|
| 90 | </p> |
---|
| 91 | <p>This is just one of many examples where MATLAB makes extensive use of functions. Another is toolboxes available from The MathWorks |
---|
| 92 | and third parties, which are largely just collections of trusted, proven, standard functions. |
---|
| 93 | </p> |
---|
| 94 | <p>In addition, many MATLAB users write their own custom functions and toolboxes.</p> |
---|
| 95 | <h2>Different function declarations<a name="2"></a></h2> |
---|
| 96 | <p>MATLAB 7 allows three types of <tt>function</tt> declarations within an m-file. To learn more, see the associated online documentation. |
---|
| 97 | </p> |
---|
| 98 | <div> |
---|
| 99 | <ul> |
---|
| 100 | <li>Primary M-File Function <a href="http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/ch_func8.shtml">http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/ch_func8.shtml</a></li> |
---|
| 101 | </ul> |
---|
| 102 | </div> |
---|
| 103 | <div> |
---|
| 104 | <ul> |
---|
| 105 | <li>Subfunctions <a href="http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/ch_fun14.shtml">http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/ch_fun14.shtml</a></li> |
---|
| 106 | </ul> |
---|
| 107 | </div> |
---|
| 108 | <div> |
---|
| 109 | <ul> |
---|
| 110 | <li>Nested Functions <a href="http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/ch_func9.shtml">http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/ch_func9.shtml</a></li> |
---|
| 111 | </ul> |
---|
| 112 | </div> |
---|
| 113 | <h2>Problem: How many functions inside an m-file?<a name="3"></a></h2> |
---|
| 114 | <p>With all this programming flexibility, it's not uncommon for an m-file to contain numerous <tt>function</tt> declarations. The MATLAB Editor provides a pull-down tool to Show Functions within an open m-file. |
---|
| 115 | </p> |
---|
| 116 | <p>Suppose you want to see <tt>function</tt> decalarations inside an m-file without editing. Perhaps you need to debug GUI callbacks, or understand someone else's function. |
---|
| 117 | You may not remember everything in a long list of functions after the Show Functions pull-down disappears. In these situations |
---|
| 118 | it would be helpful if the function list would hang around for reference. |
---|
| 119 | </p> |
---|
| 120 | <h2>Solution: custom command-line utility<a name="4"></a></h2> |
---|
| 121 | <p>To solve this problem, I created a command-line utility function, called <tt>SubFuns</tt>. Like all good MATLAB programs, <tt>SubFuns</tt> includes Help text. |
---|
| 122 | </p><pre class="codeinput">help <span class="string">SubFuns</span> |
---|
| 123 | </pre><pre class="codeoutput"> SUBFUNS lists all function declaration lines in specified MFILE. |
---|
| 124 | SUBFUNS(MFILE) displays list to Command Window. |
---|
| 125 | |
---|
| 126 | Example: |
---|
| 127 | SubFuns SubFuns |
---|
| 128 | |
---|
| 129 | Note: |
---|
| 130 | This utility uses both subfunctions and a nested function, both of |
---|
| 131 | which are supported. |
---|
| 132 | |
---|
| 133 | |
---|
| 134 | |
---|
| 135 | </pre><h2>Example<a name="5"></a></h2> |
---|
| 136 | <p><tt>SubFuns</tt> is a MATLAB function that contains all three kinds of <tt>function</tt> declarations. To see these functions we can run <tt>SubFuns</tt> on itself. |
---|
| 137 | </p><pre class="codeinput">SubFuns <span class="string">SubFuns</span> |
---|
| 138 | </pre><pre class="codeoutput"> Line: Function: |
---|
| 139 | 1 SubFuns |
---|
| 140 | 77 FunctionName |
---|
| 141 | 94 NoLeadBlanks |
---|
| 142 | 152 OpenLink |
---|
| 143 | |
---|
| 144 | </pre><p class="footer"><br> |
---|
| 145 | Published with MATLAB® 7.0<br></p> |
---|
| 146 | <!-- |
---|
| 147 | ##### SOURCE BEGIN ##### |
---|
| 148 | %% |
---|
| 149 | % Introducing |SubFuns|, a command-line utility to list all |function| |
---|
| 150 | % declarations within a specified m-file. |
---|
| 151 | |
---|
| 152 | %% MATLAB functions |
---|
| 153 | % Functions are an integral part of MATLAB. They provide higher levels of |
---|
| 154 | % functionality and abstraction. For example, the standard deviation of a |
---|
| 155 | % matrix is the square root of the variance, where the variance is the sum |
---|
| 156 | % of the squares of the elements divided by the total number of elements. |
---|
| 157 | % So, in MATLAB the |std| function calls the |var| function, which in turn |
---|
| 158 | % calls the |sum| function. |
---|
| 159 | % |
---|
| 160 | % This is just one of many examples where MATLAB makes extensive use of |
---|
| 161 | % functions. Another is toolboxes available from The MathWorks and third |
---|
| 162 | % parties, which are largely just collections of trusted, proven, standard |
---|
| 163 | % functions. |
---|
| 164 | % |
---|
| 165 | % In addition, many MATLAB users write their own custom functions and |
---|
| 166 | % toolboxes. |
---|
| 167 | |
---|
| 168 | %% Different function declarations |
---|
| 169 | % MATLAB 7 allows three types of |function| declarations within an m-file. |
---|
| 170 | % To learn more, see the associated online documentation. |
---|
| 171 | % |
---|
| 172 | % * Primary M-File Function |
---|
| 173 | % http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/ch_func8.shtml |
---|
| 174 | % |
---|
| 175 | % * Subfunctions |
---|
| 176 | % http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/ch_fun14.shtml |
---|
| 177 | % |
---|
| 178 | % * Nested Functions |
---|
| 179 | % http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/ch_func9.shtml |
---|
| 180 | |
---|
| 181 | %% Problem: How many functions inside an m-file? |
---|
| 182 | % With all this programming flexibility, it's not uncommon for an m-file to |
---|
| 183 | % contain numerous |function| declarations. The MATLAB Editor provides a |
---|
| 184 | % pull-down tool to Show Functions within an open m-file. |
---|
| 185 | % |
---|
| 186 | % Suppose you want to see |function| decalarations inside an m-file without |
---|
| 187 | % editing. Perhaps you need to debug GUI callbacks, or understand someone |
---|
| 188 | % else's function. You may not remember everything in a long list of |
---|
| 189 | % functions after the Show Functions pull-down disappears. In these |
---|
| 190 | % situations it would be helpful if the function list would hang around for |
---|
| 191 | % reference. |
---|
| 192 | |
---|
| 193 | %% Solution: custom command-line utility |
---|
| 194 | % To solve this problem, I created a command-line utility function, called |
---|
| 195 | % |SubFuns|. Like all good MATLAB programs, |SubFuns| includes Help text. |
---|
| 196 | help SubFuns |
---|
| 197 | |
---|
| 198 | %% Example |
---|
| 199 | % |SubFuns| is a MATLAB function that contains all three kinds of |
---|
| 200 | % |function| declarations. To see these functions we can run |SubFuns| on |
---|
| 201 | % itself. |
---|
| 202 | SubFuns SubFuns |
---|
| 203 | |
---|
| 204 | ##### SOURCE END ##### |
---|
| 205 | --> |
---|
| 206 | </body> |
---|
| 207 | </html> |
---|