Documentation Center

  • Trial Software
  • Product Updates

Assign Values to Structures and Fields

You can assign values to any structure, substructure, or field in a MATLAB Function block. Here are the guidelines:

OperationConditions
Assign one structure to another structureYou must define each structure with the same number, type, and size of fields, either as Simulink.Bus objects in the base workspace or locally as implicit structure declarations (see Create Structures in MATLAB Function Blocks).

Assign one structure to a substructure of a different structure and vice versa
You must define the structure with the same number, type, and size of fields as the substructure, either as Simulink.Bus objects in the base workspace or locally as implicit structure declarations.
Assign an element of one structure to an element of another structureThe elements must have the same type and size.

For example, the following table presents valid and invalid structure assignments based on the specifications for the model described in Attach Bus Signals to MATLAB Function Blocks:

AssignmentValid or Invalid?Rationale
outbus = mystruct;ValidBoth outbus and mystruct have the same number, type, and size of fields. The structure outbus is defined by the Simulink.Bus object MainBus and mystruct is defined locally to match the field properties of MainBus.
outbus = inbus;ValidBoth outbus and inbus are defined by the same Simulink.Bus object, MainBus.
outbus1 = inbus.ele3;ValidBoth outbus1 and inbus.ele3 have the same type and size because each is defined by the Simulink.Bus object SubBus.
outbus1 = inbus;InvalidThe structure outbus1 is defined by a different Simulink.Bus object than the structure inbus.

Was this topic helpful?