In MATLAB, you can define a function within another function. These are called nested functions.
Nested functions can access variables in their parent function workspace, even after the parent function has completed execution.
Here is an example of how to define and use a nested function in MATLAB:
main.m267 chars11 lines
In the example above, nestedFunc
is defined within parentFunc
. nestedFunc
can access the input argument x
of parentFunc
even though parentFunc
has completed execution.
You can call the parentFunc
from the MATLAB command window and pass it an input argument:
main.m115 chars6 lines
As you can see, the nested function nestedFunc
was called from within parentFunc
and it was able to access the variable x
in the parent function.
gistlibby LogSnag