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.

4 M-File <strong>Programming</strong><br />

Determining Which Function Is Called<br />

When more than one function has the same name, which one does <strong>MATLAB</strong><br />

call? This sectionexplainstheprocessthat<strong>MATLAB</strong>usestomakethis<br />

decision. It covers the following topics:<br />

• “Function Scope” on page 4-54<br />

• “Precedence Order” on page 4-54<br />

• “Multiple ImplementationTypes”onpage4-56<br />

• “Querying Which Function <strong>MATLAB</strong> Will Call” on page 4-56<br />

Also keep in mind that there are certain situations in which function names<br />

can conflict with variables ofthesamename. See“PotentialConflictwith<br />

Function Names” on page 3-8for more information.<br />

Function Scope<br />

Any functions you call must first be within the scope of (i.e., visible to) the<br />

calling function or your <strong>MATLAB</strong> session. <strong>MATLAB</strong> determines if a function<br />

is in scope by searching for the function’s executable file according to a certain<br />

order (see “Precedence Order” on page 4-54).<br />

One key part of this search order is the <strong>MATLAB</strong> path. The path is an<br />

ordered list of directories that <strong>MATLAB</strong> defines on startup. You can add or<br />

remove any directories you want from the path. <strong>MATLAB</strong> searches the path<br />

for the given function name, starting at the first directory in the path string<br />

and continuing until either the function file is found or the list of directories<br />

is exhausted. If no function of that name is found, then the function is<br />

considered to be out of scope and <strong>MATLAB</strong> issues an error.<br />

Precedence Order<br />

The function precedence order determines the precedence of one function<br />

over another based on the type of function and its location on the <strong>MATLAB</strong><br />

path. <strong>MATLAB</strong> selects the correct function for a given context by applying the<br />

following function precedence rules in the order given here.<br />

For items 3 through 7 in this list, the file <strong>MATLAB</strong> searches for can be any<br />

of four types: an M- or built-in file, preparsed M-file (P-Code), compiled<br />

4-54

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

Saved successfully!

Ooh no, something went wrong!