[ MODIFIED to use the terminology 'nested functions']
Hi Sterling,
You can define nested functions within other functions as in the following example.
function z = xsixth(x)
z = xsquare(x).^3;
function a = xsquare(b)
a = b.^2
end
end
Here the nested function xsquare is local to the function xsixth, and calling xsquare from the command line results in an error. If for some reason you need the output of (in this example) xsquare, you can either define it as a separate function and no longer a nested function or do something like the following
function [z y] = xsixth(x)
z = xsquare(x).^3;
y = xsquare(x);
function a = xsquare(b)
a = b.^2
end
end
with the extra output y pulling out the result.