Prevent External Variable Initialization for Distributed Code Generation
Generate structured text code for different components of your model.
Open model
Open the model by using the following command:
open_system('External_Var_Distributed_Codegen');
Configure Model Components for Distributed Code Generation
To autogenerate structured text code by preventing initialization statements for externally defined variables for external code integration later on, use remove Initialization Statements for Externally Defined State Variables. for more information, see Remove Initialization Statements for Externally Defined State Variables.
Mark Externally Defined Variables
Open the Simulink PLC Coder app. For more information, see Simulink PLC Coder.
Select the
Subsystem
block.Click Settings. Navigate to PLC Code Generation > Identifiers. In the
Identifier Names
box enterchild1,child2,DSExportedGlobal
.Click OK.
Code Generation
Open the Simulink PLC Coder app. For more information, see Simulink PLC Coder.
Select the
Subsystem
block.Click Settings. Navigate to PLC Code Generation > Interface. Select the Remove Initialization Statements for externally defined state variables check box.
Click OK.
Generate Code for the Subsystem
To generate code for the individual subsystem use the plcgenerate code function:
plcgeneratecode('External_Var_Distributed_Codegen/Subsystem');
Related Topics
Generated Code Structure for PLC_PreventExternalVarInitialization.