MATLAB Guide

As you use MATLAB you will build up your own collection of M-files. Some may be short scripts that are intended to be used only once, but others will be of potential use in future work. Based on our experience with MATLAB we offer some guidelines on making M-files easy to use, understand, and maintain.
In Chapter 7 we explained the structure of the leading comment lines of a function, including the HI line. Adhering to this format and fully documenting the function in the leading comment lines is vital if you are to be able to reuse and perhaps modify the function some time after writing it. A further benefit is that writing the comment lines forces you to think carefully about the design of the function, including the number and ordering of the input and output arguments.
It is helpful to include in the leading comment lines an example of how the function is used, in a form that can be cut and pasted into the command line (hence function names should not be given in capitals). MATLAB functions that provide such examples include fzero, meshgrid, null and texlabel.
In formatting the code, it is advisable to follow the example of the M-files provided with MATLAB, and to use
spaces around logical operators and = in assignment statements,
one statement per line (with exceptions such as a short if),
indentation to emphasize if, for, switch and while structures (as...