Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Let's first pick MATLAB's brain on how to create functions in MATLAB. Bring up the following page in the Help navigator:from Documentation. 

Home (tab) > Documentation (icon) Help > Contents > MATLAB > User Guide > Programming Fundamentals > Functions and Scripts > M-File Scripts and Functions > M-File Functions.Functions > Function Basics > function

This page has a simple example: a function called average that calculates the average of the elements in a vector. Take a couple of minutes to peruse this example. MATLAB the examples for functions with one output and functions with multiple outputs. MATLAB has extensive documentation on the use of functions; however, one has to poke around a bit before finding the most useful information. I personally go for the examples first.

The correct syntax for creating a function is:

function return_value = function_name(parameter_1, parameter_2,...)

...