23.06.2015 Views

MATLAB Programming

MATLAB Programming

MATLAB Programming

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Private Functions<br />

Private Functions<br />

Private functions are functions that reside in subdirectories with the special<br />

name private. These functions are called private because they are visible<br />

only to M-file functions and M-file scripts that meet these conditions:<br />

• A function that calls a private function must be defined in an M-file that<br />

resides in the directory immediately above that private subdirectory.<br />

• A script that calls a private function must itself be called from an M-file<br />

function that has access to the private function according to the above rule.<br />

For example, assume the directory newmath is on the <strong>MATLAB</strong> search path. A<br />

subdirectory of newmath called private can contain functions that only the<br />

functions in newmath can call.<br />

Because private functions are invisible outside the parent directory, they can<br />

use the same names as functions in other directories. This is useful if you<br />

want to create your own version of a particular function while retaining the<br />

original in another directory. Because <strong>MATLAB</strong> looks for private functions<br />

before standard M-file functions, it will find a private function named test.m<br />

before a nonprivate M-file named test.m.<br />

Primary functions and subfunctions can also be implemented as private<br />

functions.<br />

Private Directories<br />

You can create your own private directories simply by creating subdirectories<br />

called private using the standard procedures for creating directories or<br />

folders on your computer. Do not place these private directories on your path.<br />

5-35

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!