Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

Function Basics

Create functions, including anonymous, local, and nested functions

MATLAB Language Syntax

functionDeclare function name, inputs, and outputs

Examples and How To

Create Functions in Files

This example shows how to create a function in a program file.

Add Help for Your Program

Help text appears in the Command Window when you use the help function. Create help text for your program by inserting comments at the beginning.

Run Functions in the Editor

This example shows how to run a function that requires some initial setup, such as input argument values, while working in the Editor.

Concepts

Types of Functions

There are several types of functions available with MATLAB®, including local functions, nested functions, private functions, and anonymous functions.

Function Precedence Order

To determine which function to call when multiple functions in the current scope have the same name, MATLAB uses function precedence order.

Troubleshooting

Variables in Nested and Anonymous Functions

Variables used within nested and anonymous functions must be present in the text of the code. If you add a variable to the workspace of an anonymous function, a nested function, or a function that contains a nested function dynamically, MATLAB issues an error.

Was this topic helpful?