Create MATLAB header

Language: Python

Last modified: 15 August 2006

The first few commented lines of a MATLAB function are used as help documentation for the function. This script makes it easy to generate a consistent header for your functions and is most useful when run from within a text editor, such as Vim or BBEdit.

Get the script

Vim setup

Add the following lines to your vimrc file where <path to script> is the complete path to the script. With these settings, the script can be run by placing the cursor on the line with the function declaration and typing ‘,mh’ - comma then m then h.

" ,mh apply matlab header
nmap ,mh :.!/path/to/script/MatlabHeader.py<CR>
vmap ,mh !/path/to/script/MatlabHeader.py<CR>

BBEdit or TextWrangler setup

The script or an alias to the script should be installed in the Unix Filters directory - see the manual for the location of this directory. Once installed, you select the function declaration and run the script.

Sample input and output

When run on the following function declaration:

function [out1,out2] = testfunction(in1,in2)

The script produces the following header:

%testfunction
%
%        
%
% -Usage-
%        [out1,out2] = testfunction(in1,in2)
%
% -Inputs-
%        in1
%        in2
%
% -Outputs-
%        out1
%        out2
%
% Last Modified: 01/26/2009

You can customize the header by editing the template at the top of the script.