카테고리 없음

Create Function

오늘보다 나은 내일 2016. 4. 15. 14:42

Create Function Handle


You can create function handles to named and anonymous functions. You can store multiple function handles in an array, and save and load them, as you would any other variable.


What Is a Function Handle?

A function handle is a MATLAB® data type that stores an association to a function. Indirectly calling a function enables you to invoke the function regardless of where you call it from. Typical uses of function handles include:


Pass a function to another function (often called function functions). For example, passing a function to integration and optimization functions, such as integral and fzero.

Specify callback functions. For example, a callback that responds to a UI event or interacts with data acquisition hardware.

Construct handles to functions defined inline instead of stored in a program file (anonymous functions).

Call local functions from outside the main function.

You can see if a variable, h, is a function handle using isa(h,'function_handle').


Creating Function Handles

To create a handle for a function, precede the function name with an @ sign. For example, if you have a function called myfunction, create a handle named f as follows:


f = @myfunction;

You call a function using a handle the same way you call the function directly. For example, suppose that you have a function named computeSquare, defined as: