## Documentation Center |

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

Operation | Conditions |
---|---|

Assign one structure to another structure | You 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 structure | The 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:

Assignment | Valid or Invalid? | Rationale |
---|---|---|

outbus = mystruct; | Valid | Both 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; | Valid | Both outbus and inbus are
defined by the same Simulink.Bus object, MainBus. |

outbus1 = inbus.ele3; | Valid | Both outbus1 and inbus.ele3 have
the same type and size because each is defined by the Simulink.Bus object SubBus. |

outbus1 = inbus; | Invalid | The structure outbus1 is defined by a different Simulink.Bus object
than the structure inbus. |

Was this topic helpful?