Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

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.

Related Examples

More About

Was this topic helpful?