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.

Calling Functions<br />

C or Fortran file (MEX-file), or Simulink ® model (MDL-file). See “Multiple<br />

Implementation Types” on page 4-56 for more on this.<br />

1 Variable<br />

Before assuming that a name should match a function, <strong>MATLAB</strong> checks<br />

the current workspace to see if it matches a variable name. If <strong>MATLAB</strong><br />

finds a match, it stops the search.<br />

2 Subfunction<br />

Subfunctions take precedence over all other M-file functions and overloaded<br />

methods that are on the path and have the same name. Even if the function<br />

is called with an argument of type matching that of an overloaded method,<br />

<strong>MATLAB</strong> uses the subfunction and ignores the overloaded method.<br />

3 Private function<br />

Private functions are called if there is no subfunction of the same name<br />

within the current scope. As with subfunctions, even if the function is<br />

called with an argument of type matching that of an overloaded method,<br />

<strong>MATLAB</strong> uses the private function and ignores the overloaded method.<br />

4 Class constructor<br />

Constructor functions (functions having names that are the same as the @<br />

directory, for example @polynom/polynom.m) take precedence over other<br />

<strong>MATLAB</strong> functions. Therefore, if you create an M-file called polynom.m and<br />

put it on your path before the constructor @polynom/polynom.m version,<br />

<strong>MATLAB</strong> will always call the constructor version.<br />

5 Overloaded method<br />

<strong>MATLAB</strong> calls an overloaded method if it is not superseded by a<br />

subfunction or private function. Which overloaded method gets called<br />

dependsontheclassesoftheobjectspassedintheargumentlist.<br />

6 Function in the current directory<br />

A function in the current working directory is selected before one elsewhere<br />

on the path.<br />

4-55

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

Saved successfully!

Ooh no, something went wrong!