Introducing SubFuns, a command-line utility to list all function declarations within a specified m-file.

Contents

MATLAB functions

Functions are an integral part of MATLAB. They provide higher levels of functionality and abstraction. For example, the standard deviation of a matrix is the square root of the variance, where the variance is the sum of the squares of the elements divided by the total number of elements. So, in MATLAB the std function calls the var function, which in turn calls the sum function.

This is just one of many examples where MATLAB makes extensive use of functions. Another is toolboxes available from The MathWorks and third parties, which are largely just collections of trusted, proven, standard functions.

In addition, many MATLAB users write their own custom functions and toolboxes.

Different function declarations

MATLAB 7 allows three types of function declarations within an m-file. To learn more, see the associated online documentation.

Problem: How many functions inside an m-file?

With all this programming flexibility, it's not uncommon for an m-file to contain numerous function declarations. The MATLAB Editor provides a pull-down tool to Show Functions within an open m-file.

Suppose you want to see function decalarations inside an m-file without editing. Perhaps you need to debug GUI callbacks, or understand someone else's function. You may not remember everything in a long list of functions after the Show Functions pull-down disappears. In these situations it would be helpful if the function list would hang around for reference.

Solution: custom command-line utility

To solve this problem, I created a command-line utility function, called SubFuns. Like all good MATLAB programs, SubFuns includes Help text.

help SubFuns
 SUBFUNS lists all function declaration lines in specified MFILE.
    SUBFUNS(MFILE) displays list to Command Window.
 
 Example:
    SubFuns SubFuns
 
 Note:
    This utility uses both subfunctions and a nested function, both of
    which are supported.



Example

SubFuns is a MATLAB function that contains all three kinds of function declarations. To see these functions we can run SubFuns on itself.

SubFuns SubFuns
   Line:   Function:
   1       SubFuns
   77      FunctionName
   94      NoLeadBlanks
   152     OpenLink