Documentation Center

  • Trial Software
  • Product Updates

Create Structures in MATLAB Function Blocks

Here is the workflow for creating a structure in a MATLAB Function block:

  1. Decide on the type (or scope) of the structure (see Types of Structures in MATLAB Function Blocks).

  2. Based on the scope, follow these guidelines for creating the structure:

    For Structure Scope:Follow These Steps:
    Input
    1. Create a Simulink.Bus object in the base workspace to define the structure input.

    2. Add data to the MATLAB Function block, as described in Adding Data to a MATLAB Function Block. The data should have the following properties

      • Scope = Input

      • Type = Bus: <object name>

        For <object name>, enter the name of the Simulink.Bus object that defines the structure input

    See Rules for Defining Structures in MATLAB Function Blocks.

    Output
    1. Create a Simulink.Bus object in the base workspace to define the structure output.

    2. Add data to the MATLAB Function block with the following properties:

      • Scope = Output

      • Type = Bus: <object name>

        For <object name>, enter the name of the Simulink.Bus object that defines the structure output

    3. Define and initialize the output structure implicitly as a variable in the MATLAB® function, as described in Structure Definition for Code Generation.

    4. Make sure the number, type, and size of fields in the output structure variable definition match the properties of the Simulink.Bus object.

    Local

    Define the structure implicitly as a local variable in the MATLAB function, as described in Structure Definition for Code Generation. By default, local variables in MATLAB Function blocks are temporary.

    Persistent

    Define the structure implicitly as a persistent variable in the MATLAB function, as described in Make Structures Persistent.

    Parameter
    1. Create a structure variable in the base workspace.

    2. Add data to the MATLAB Function block with the following properties:

      • Name = same name as the structure variable you created in step 1.

      • Scope = Parameter

    See Define and Use Structure Parameters.

Was this topic helpful?