Programming Previous page   Next Page

Overloaded MATLAB Functions

An overloaded function is an additional implementation of an existing function that has been designed specifically to handle a certain data type. When you pass an argument of this type in a call to the function, MATLAB looks for the function implementation that handles that type and executes that function code.

Each overloaded MATLAB function has an M-file on the MATLAB path. The M-files for a certain data type (or class) are placed in a directory named with an @ sign followed by the class name. For example, to overload the MATLAB plot function to plot expressions of a class named polynom differently than other data types, you would create a directory called @polynom and store your own version of plot.m in that directory.

You can add your own overloads to any function by creating a class directory for the data type you wish to support for that function, and creating an M-file that handles that type in a manner different from the default. See Setting Up Class Directories and Designing User Classes in MATLAB.

When you use the which command with the -all option, MATLAB returns all occurrences of the file you are looking for. This is an easy way to find functions that are overloaded:


Previous page  Built-In Functions M-File Programming Next page

© 1994-2005 The MathWorks, Inc.