In addition to making scripts, we can also create functions. If they are stored in a location that is in the Matlab path, they can be used as a toolkit to help limit repeated code used for common tasks.
Matlab functions are also created in an m-file, however the file is initiated with the following
function [output_parameters] = <function_name>(input_parameters}
The with an ``.m'' extension must be the name of the m-file. To create a function that adds two numbers for example, your function may be called ``myadd'', and your m-file would be called ``myadd.m'' and would contain the following
function y = myadd(a, b) % MYADD -- adds two numbers a and b % % See also SUM. y = a+b;