| Stateflow® | ![]() |
| On this page… |
|---|
Embedded MATLAB™ functions support MATLAB® structures. You can create structures in top-level Embedded MATLAB functions in Stateflow® charts to interface with Simulink® bus signals at input and output ports. Simulink buses appear inside the Embedded MATLAB function as structures; structure outputs from the Embedded MATLAB function appear as buses.
You can also create structures as local and persistent variables in top-level functions and subfunctions of Embedded MATLAB functions.
This section describes how to define structures in Embedded MATLAB functions.
Follow these rules when defining structures in Embedded MATLAB functions in Stateflow charts:
For each structure input or output in an Embedded MATLAB function, you must define a Simulink.Bus object in the base workspace to specify its type to the Simulink signal.
Embedded MATLAB structures cannot inherit their type from Simulink signals.
Embedded MATLAB functions support nonvirtual buses only (see Virtual and Nonvirtual Buses in the Simulink User's Guide).
Structures cannot have scopes defined as Parameter or Constant.
When you create structure inputs in Embedded MATLAB functions, the function determines the type, size, and complexity of the structure from the Simulink input signal. When you create structure outputs, you must define their type, size, and complexity in the Embedded MATLAB function.
You can connect Embedded MATLAB structure inputs and outputs to any Simulink bus signal, including:
Simulink blocks that output bus signals — such as Bus Creator blocks
Simulink blocks that accept bus signals as input — such as Bus Selector and Gain blocks
S-Function blocks
Other Embedded MATLAB functions
To define structure inputs and outputs in Embedded MATLAB functions in Stateflow charts, follow these steps:
Create a Simulink bus object in the base workspace to specify the properties of the structure you will create in the Embedded MATLAB function.
For information about how to create Simulink bus objects, see Simulink.Bus in the Simulink Reference.
In the Embedded MATLAB Editor, open the Model Explorer by selecting Tools > Model Explorer.
In the Model Explorer, follow these steps:
In the Model Hierarchy pane, select the Embedded MATLAB function in your Stateflow chart.
Add a data object, as described in Adding Data Using the Model Explorer.
The Model Explorer adds a data object and opens a Properties dialog box in its right-hand Dialog pane.
In the Properties dialog box, enter the following information in the General tab fields:
| Field | What to Specify |
|---|---|
| Name | Enter a name for referencing the structure in the Embedded MATLAB function. This name does not have to match the name of the bus object in the base workspace. |
| Scope | Select Input or Output. |
| Type | Select Bus: <bus object name> from the drop-down list. Then, replace "<bus object name>" with the name of the Simulink.Bus object in the base workspace that defines the structure. For example: Bus: inbus. |
To add or modify Simulink.Bus objects,
click the Show data type assistant button
to display the Data Type
Assistant. Then, click the Edit button to bring
up the Simulink Bus Types Editor (see Using Bus Objects in the Simulink User's
Guide).
Click Apply.
If your structure is an output (has scope of Output), define the output implicitly in the Embedded MATLAB function to have the same type, size, and complexity as its Simulink.Bus object, as described in About Structures in the Embedded MATLAB™ Subset in the Embedded MATLAB User's Guide.
You can define structures as local or persistent variables inside Embedded MATLAB functions (see Types of Structures in the Embedded MATLAB™ Subset in the Embedded MATLAB User's Guide).
![]() | Model Coverage for an Embedded MATLAB™ Function | Building Targets | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |