Programming Previous page   Next Page

Private Functions

Private functions are functions that reside in subdirectories with the special name private. These functions are called private because they are visible only to M-file functions and M-file scripts that meet these conditions:

For example, assume the directory newmath is on the MATLAB search path. A subdirectory of newmath called private can contain functions that only the functions in newmath can call.

Because private functions are invisible outside the parent directory, they can use the same names as functions in other directories. This is useful if you want to create your own version of a particular function while retaining the original in another directory. Because MATLAB looks for private functions before standard M-file functions, it will find a private function named test.m before a nonprivate M-file named test.m.

Primary functions and subfunctions can also be implemented as private functions.

Private Directories

You can create your own private directories simply by creating subdirectories called private using the standard procedures for creating directories or folders on your computer. Do not place these private directories on your path.

Accessing Help for a Private Function

You can write help for private functions using the same rules that apply to primary functions. To display the help for a private function, precede the private function name with private/.

For example, to get help on private function myprivfun, type


Previous page  Subfunctions Overloaded Functions Next page

© 1994-2005 The MathWorks, Inc.