Skip to main content

13.8) Writing Functions (cont'd)


  • It is good practice to include help and comments in your functions
  • A detailed help section within a function will help others understand and use your functions, it will also allow you, a few months later, to understand what the function does and how it should be used. Here help and comments become invaluable
  • Lets add comments to our function MyFirstFunction

[matlab]
function [out] = MyFirstFunction(a,b)
>> %MyFirstFunction - adds two scalars together
>> %%
>> Syntax: out=MyFirstFunction(a,b)
>> %Inputs
>> % a and b are equal sized arrays containing the same Class
>> %Outputs
>> % out is the same size array as a and b and of the same Class
>> %Other M-Functions required - none
>> %%
>> Author - A.N. Other
>> %School of Earth and Environment, University of Leeds, UK
>> %Last revision 01-January-2014
>> %-----BEGIN CODE
>> out=a+b;
>> %-----END CODE
[/matlab]