| Stateflow® | ![]() |
| On this page… |
|---|
Any source of data, events, or code that is outside a Stateflow chart, its Stateflow machine, or its Simulink model, is considered external to that Stateflow chart. You can interface data and events from external sources to your Stateflow chart. See Defining Data and Defining Events for information on defining data and events.
You can include external source code in the Simulation Target > Custom Code pane of the Configuration Parameters dialog box. (For details, see Building Targets.)
You might want an external source (outside the Stateflow chart, its Stateflow machine, and its Simulink model) to be able to access a data object. By defining a data object's scope as Exported, you make it accessible to external sources. Exported data must be parented by the Stateflow machine, because the machine has the highest level in the Stateflow hierarchy and can interface to external sources. The Stateflow machine also retains the ability to access the exported data object. Exporting the data object does not imply anything about what the external source does with the data. It is the responsibility of the external source to include the exported data object (in the manner appropriate to the source) to make use of the right to access the data.
If the external source is another Stateflow machine, then that machine defines an exported data object, and the other machine defines the same data object as Imported. Stateflow software generates the appropriate export and import data code for both machines.
The following example shows the format required in the external code source (custom code) to import a Stateflow exported data object:

Similarly, you might want to access a data object that is externally defined outside the Stateflow chart, its Stateflow machine, and its Simulink model. If you define the data's scope as Imported, the data can be accessed anywhere within the hierarchy of the Stateflow machine (including any offspring of the machine). An imported data object's parent is external. However, the data object needs an adoptive parent to resolve symbols for code generation. An imported data object's adoptive parent must be the Stateflow machine, because the machine has the highest level in the Stateflow hierarchy and can interface to external sources. It is the responsibility of the external source to make the imported data object available (in the manner appropriate to the source).
If the external source for the data is another Stateflow machine, that machine must define the same data object as Exported. Stateflow software generates the appropriate import and export data code for both machines.
This example shows the format required to retrieve imported data from an external code source (custom code).

You might want an external source (outside the Stateflow chart, its Stateflow machine, and its Simulink model) to be able to broadcast an event. By defining an event's scope to be Exported, you make that event available to external sources for broadcast purposes. Exported events must be parented by the Stateflow machine, because the machine has the highest level in the Stateflow hierarchy and can interface to external sources. The Stateflow machine also retains the ability to broadcast the exported event. Exporting the event does not imply anything about what the external source does with the information. It is the responsibility of the external source to include the Exported event (in the manner appropriate to the source) to make use of the right to broadcast the event.
If the external source for the event is another Stateflow machine, then that machine must define the event as an Exported event, and the other machine must define the same event as Imported. Stateflow software generates the appropriate export and import event code for both machines.
Consider a real-world example to clarify when to define an Exported event. You have purchased a communications pager. There are a few people you want to be able to page you, so you give those people your personal pager number. These people now know your pager number and can call that number and page you at any time. You do not usually page yourself, but you can do so. Telling someone the pager number does not mean they have heard and recorded the number. It is the other person's responsibility to retain the number.
This example shows the format required in the external code source (custom code) to take advantage of an Exported event.

You might want to broadcast an event that is defined externally (outside the Stateflow chart, its Stateflow machine, and its Simulink model). By defining an event's scope to be Imported, you can broadcast the event anywhere within the hierarchy of that machine (including any offspring of the machine).
An imported event's parent is external. However, the event needs an adoptive parent to resolve symbols for code generation. An imported event's adoptive parent must be the Stateflow machine, because the machine has the highest level in the Stateflow hierarchy and can interface to external sources. It is the responsibility of the external source to make the imported event available (in the manner appropriate to the source).
If the external source is another Stateflow machine, the source machine must define the same event as Exported. Stateflow software generates the appropriate import and export event code for both machines.
The preceding pager example for exported events can clarify the use of imported events. For example, someone buys a pager and tells you that you might want to use this number to page them in the future, and they give you the pager number to record. You can then use that number to page that person.
The following example shows the format required in an external code source (custom code) to generate an Imported event.

![]() | MATLAB Workspace Interfaces | Working with Structures and Bus Signals in Stateflow Charts | ![]() |
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |