Functions
Code that accepts inputs and returns outputs
MATLAB® includes a wide range of predefined functions for computational tasks. For basics on how to call these functions, see Calling Functions.
As you write code, you can define your own functions to reuse a sequence of commands. For instance, create a function in a program file to calculate the area of a circle.
function A = areaCircle(R) rSquared = R.^2; A = pi.*rSquared; end
r = 10; a = areaCircle(r);
For more information, see Create Functions in Files.
Categories
- Function Creation
Create functions, including anonymous, local, and nested functions
- Argument Definitions
Accept a variable number of inputs or outputs, check for valid values
- Scope Variables and Generate Names
Share data between functions or workspaces, generate valid variable names
- Error Handling
Generate, catch, and respond to warnings and errors