Main Content

Generated Code Structure for MATLAB Function Block

This topic assumes that you have generated Structured Text code from a Simulink® model. If you have not yet done so, see Generate Structured Text from the Model Window.

The example in this topic shows generated code for the CODESYS Version 2.3 IDE. Generated code for other IDE platforms looks different.

  1. Open the plcdemo_eml_tankcontrol model. To open the model, enter:

    openExample('plcdemo_eml_tankcontrol');

  2. Open the PLC Coder app. Click the PLC Code tab.

  3. Click Generate PLC Code.

    The Simulink PLC Coder™ software generates Structured Text code and places it in current_folder/plcsrc/plcdemo_eml_tankcontrol.exp.

  4. If you do not have the plcdemo_eml_tankcontrol.exp file open, open it in the MATLAB® editor.

    The following figure illustrates the mapping of the generated code to Structured Text components for a Simulink Subsystem block that contains a MATLAB Function block. The coder tries to perform inline optimization on the generated code for MATLAB local functions. If the coder determines that it is more efficient to leave the local function as is, it places the generated code in a Structured Text construct called FUNCTION.

  5. Examine the generated Structured Text code.