Creating new functions -- .m files
New functions can be defined by storing the commands to compute them in a file with a name that exactly matches the function name followed by .m .
Function definition syntax:
function [output vars ] = function_name ( input vars )
function [result] = sqr(x);
% yield the square of the values in x
All variables are local to the function.
Comments that immediately follow the function definition line are used by help and lookfor
Functions may be applied to any Matlab data and will be applied element-by-element automatically if appropriate.