| Programming and Data Types | ![]() |
Fields Returned by the Functions Command
The functions command returns a MATLAB structure with the fields function, type, file, and, for overloaded functions, methods. This section describes each of those fields.
Function Name
The function field is a character array that holds the name of the function corresponding to the function handle.
The type field is a character array that holds one of five possible strings listed in the following table.
The contents of the next two fields, file and methods, depend upon the function type.
Function File
The file field is a character array that holds one of the following:
MATLAB built-in function', for built-in functions
The default function is the one function implementation that is not specialized to operate on any particular data type. Unless the arguments in the function call specify a class that has a specialized version of the function defined, it is the default function that gets called.
The example below operates on a function handle for the deblank function. The function has a default implementation in the strfun directory. This is shown in f.file. It also has an overloaded method in the @cell directory. This is shown in f.methods.cell.
f = functions(@deblank) f = function: 'deblank' type: 'overloaded' file: 'matlabroot\toolbox\matlab\strfun\deblank.m' methods: [1x1 struct] f.methods ans = cell: 'matlabroot\toolbox\matlab\strfun\@cell\deblank.m'
If you evaluate the @deblank function handle with a cell argument, MATLAB calls the deblank method in the @cell directory. But, for any other argument types, MATLAB calls the default M-file shown in the file field.
Function Methods
The methods field exists only for functions of type, overloaded. This field is a separate MATLAB structure that identifies all overloaded methods that are bound to the function handle.
The structure contains one field for each method of the function handle. The field names are the classes that overload the function. Each field value is a character array holding the path and name of the source file that defines the method.
For example, a function handle for the display function may be bound to the M-files shown below. The functions command returns a methods structure having a field for each class overloading the function: polynom, inline, serial, and avifile. For each class, it shows the path and name of the method source file.
f = functions(@display); f.methods ans = polynom: '\home\user4\@polynom\display.m' inline: 'matlabroot\toolbox\matlab\funfun\@inline\display.m' serial: 'matlabroot\toolbox\matlab\iofun\@serial\display.m' avifile: 'matlabroot\toolbox\matlab\iofun\@avifile\display.m'
| Displaying Function Handle Information | Types of Function Handles | ![]() |