Programming and Data Types    

Types of Function Handles

The information returned by functions varies depending on the type of function represented by the function handle. This section explains what is returned for each type of function. The categories of function handles are:

Simple Function Handles

These are handles to nonoverloaded MATLAB built-in or M-file functions. Any function handles for which the function type has not yet been determined (e.g., Java methods, nonexistent functions), also fall into this category.

Structure fields:

Examples:

Using functions on a function handle to a built-in function

Using functions on a function handle to a nonbuilt-in function

Overloaded Function Handles

These are handles to MATLAB built-in or M-file functions that are overloaded implementations for different classes.

Structure fields:

Examples:

Using functions on a function handle to a built-in function

Using functions on a function handle to a nonbuilt-in function

Constructor Function Handles

These are handles to functions that construct objects of MATLAB classes.

Structure fields:

Example:

Using functions on a function handle to a constructor function

Subfunction Handles

These are handles to MATLAB subfunctions, which are functions defined within an M-file that are only visible to the primary function of that M-file. When you use functions on a subfunction handle, the file field of the return structure contains the path and name of the M-file in which the subfunction is defined.

Structure fields:

Example:

The getLocalHandle M-file, shown below, defines a primary function and a subfunction, named subfunc.

A call to getLocalHandle returns a function handle to the subfunction. When you pass that handle to functions, it returns the following information.

Private Function Handles

These are handles to MATLAB private functions, which are functions defined in a private subdirectory that are only visible to functions in the parent directory. When you use functions on a private function handle, the file field of the return structure contains the path and name of the M-file in the private subdirectory that defines the function.

Structure fields:

Example:

The getPrivateHandle function, shown below, returns a handle to a private function named privatefunc.

The following function, privatefunc, resides in the \private subdirectory.

A call to getPrivateHandle returns a handle to the function, privatefunc, defined in \private. When you pass that handle to functions, it returns the following information.


  Fields Returned by the Functions Command Function Handle Operations