| Contents | Index |
| On this page… |
|---|
Any source of data 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 from external sources to your Stateflow chart. For information on defining data, see Defining Data.
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 chart and the model) to be able to access a data object. By defining the scope of a data object as Exported, you make it accessible to external sources. Exported data must be parented by the Stateflow machine, because the machine is 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.
Suppose that you want to export a Stateflow data object named ext_data. Follow these steps:
In your Stateflow machine, define data named ext_data of Exported scope.
Define ext_data as imported in the external code source (custom code) using the following format:
extern int ext_data;
void func_example(void)
{
...
ext_data = 123;
...
}Stateflow software generates the following code for the exported data:
int ext_data;
Similarly, you might want to access a data object that is defined outside the chart and the model. If you define the scope of the data as Imported, you can access the data anywhere in the hierarchy of the Stateflow machine. The parent of an imported data object is external. However, the data object needs an adoptive parent to resolve symbols for code generation. The adoptive parent of an imported data object must be the Stateflow machine, because the machine is the highest level in the 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.
Suppose that you want to import a Stateflow data object named ext_data. Follow these steps:
In your Stateflow machine, define data named ext_data of Imported scope.
Define ext_data as exported in the external code source (custom code) using the following format:
int ext_data;
void func_example(void)
{
...
}Stateflow software generates the following code for the imported data:
extern int ext_data;
![]() | MATLAB Workspace Interfaces | Working with Structures and Bus Signals in Stateflow Charts | ![]() |

Learn how engineers use Stateflow to model state machines in their Simulink models.
| © 1984-2012- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |