| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → MATLAB |
| Contents | Index |
| Learn more about MATLAB |
| On this page… |
|---|
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:
A function that calls a private function must be defined in a program file that resides in the folder immediately above that private subfolder.
A script that calls a private function must itself be called from a function that has access to the private function according to the above rule.
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.
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.
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
![]() | Subfunctions | Overloaded Functions | ![]() |

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 |