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.

Nested Functions<br />

Example — More Than One Nested Function<br />

This example shows function A and two additional functions nested inside A<br />

at the same level:<br />

function x = A(p1, p2)<br />

...<br />

function y = B(p3)<br />

...<br />

end<br />

function z = C(p4)<br />

...<br />

end<br />

...<br />

end<br />

Example — Multiply Nested Functions<br />

This example shows multiply nested functions, C nested inside B, andB in A:<br />

function x = A(p1, p2)<br />

...<br />

function y = B(p3)<br />

...<br />

function z = C(p4)<br />

...<br />

end<br />

...<br />

end<br />

...<br />

end<br />

Calling Nested Functions<br />

You can call a nested function<br />

• From the level immediately above it. (In the following code, function A can<br />

call B or D, but not C or E.)<br />

• From a function nested at the same level within the same parent function.<br />

(Function B can call D, and D can call B.)<br />

5-17

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

Saved successfully!

Ooh no, something went wrong!