Code Generation for Nested Functions
You can generate code for MATLAB®functions that contain nested functions. For example, you can generate code for the functionparent_fun
, which contains the nested functionchild_fun
.
functionparent_funx = 5; child_funfunctionchild_fun x = x + 1;endend
Nested Function Limitations for Code Generation
当你为neste生成代码d functions, you must adhere to the code generation restrictions for value classes, cell arrays, and handle classes. You must also adhere to these restrictions:
If the parent function declares a persistent variable, it must assign the persistent variable before it calls a nested function that uses the persistent variable.
A nested recursive function cannot refer to a variable that the parent function uses.
If a nested function refers to a structure variable, you must define the structure by using
结构体
.If a nested function uses a variable defined by the parent function, you cannot use
coder.varsize
with the variable in either the parent or the nested function.