Generate Structured Text Code for a MATLAB Function Block
This example shows how to model, simulate, and generate code for a Simulink® subsystem that has a MATLAB® Function Block. Generate code for the MATLAB Function Block by using Simulink PLC Coder™.
The model consists of these components:
TankControl —MATLAB Function block that takes the tank height and valve command as inputs and generates the tank input flow rate, output flow rate, and stirrer speed.
Tank Dynamics —Simulink subsystem that models the dynamics of the tank.
Signal Builderblock that models the valve command to the
Open the model.
Simulate the model and verify the valve operation by changing the tank height, flow rates, and other parameters. After verifying that the
TankControl block functions according to your requirements, generate code for the
To generate structured text code, do one of the following:
Open the PLC Coder app. Select the
SimpleSubsystemblock and click
Generate PLC Code.
### Generating PLC code for 'plcdemo_eml_tankcontrol/TankControl'. ### Using model settings from 'plcdemo_eml_tankcontrol' for PLC code generation parameters. ### Begin code generation for IDE codesys23. ### Emit PLC code to file. ### PLC code generation successful for 'plcdemo_eml_tankcontrol/TankControl'. ### Generated files: ./plcsrc/plcdemo_eml_tankcontrol.exp