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.

5 Types of Functions<br />

• From a function at any lower level. (Function C can call B or D, but not E.)<br />

function A(x, y)<br />

B(x, y);<br />

D(y);<br />

function B(x, y)<br />

C(x);<br />

D(y);<br />

function C(x)<br />

D(x);<br />

end<br />

end<br />

function D(x)<br />

E(x);<br />

function E(x)<br />

...<br />

end<br />

end<br />

end<br />

% Primary function<br />

% Nested in A<br />

% Nested in B<br />

% Nested in A<br />

% Nested in D<br />

You can also call a subfunction from any nested function in the same M-file.<br />

You can pass variable numbers of arguments to and from nested<br />

functions, but you should be aware of how <strong>MATLAB</strong> interprets varargin,<br />

varargout, nargin, andnargout under those circumstances. See "Passing<br />

Optional Arguments to Nested Functions" in the <strong>MATLAB</strong> <strong>Programming</strong><br />

documentation for more information on this.<br />

Note If you construct a function handle for a nested function, you can call the<br />

nested function from any <strong>MATLAB</strong> function that has access to the handle.<br />

See “Using Function Handles with Nested Functions” on page 5-21.<br />

5-18

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

Saved successfully!

Ooh no, something went wrong!