Products & Services Solutions Academia Support User Community Company

Learn more about MATLAB   

Private Functions

Overview

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

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

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

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

Private Folders

You can create your own private folders simply by creating subfolders called private using the standard procedures for creating folders on your computer. Do not place these private folders 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

help private/myprivfun
  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2010- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS