Programming and Data Types    


Functions are M-files that accept input arguments and return output arguments. They operate on variables within their own workspace. This is separate from the workspace you access at the MATLAB command prompt.

This section covers the following topics regarding functions:

Simple Function Example

The average function is a simple M-file that calculates the average of the elements in a vector.

If you would like, try entering these commands in an M-file called average.m. The average function accepts a single input argument and returns a single output argument. To call the average function, enter

  Scripts Basic Parts of a Function M-File