This is machine translation

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

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Map Variables for Atomic Subcharts and Boxes

An atomic subchart is a graphical object that helps you to create standalone subcomponents in a Stateflow® chart. Atomic subcharts are supported only in Stateflow charts in Simulink® models. For more information, see Create Reusable Subcomponents by Using Atomic Subcharts.

To ensure that each variable in your atomic subchart or atomic box maps to the correct data in the main chart, edit the mapping on the Mappings tab in the Properties dialog box. For each atomic subchart variable, in the Main chart symbol field, you can select the name of the corresponding symbol from the drop-down list. Alternatively, you can type an expression specifying:

If you leave the Main chart symbol field empty, then Stateflow attempts to map the atomic subchart variable to a main chart variable with the same name.

You can map a variable in the atomic subchart to a symbol in the main chart that has a different scope. This table lists the possible mappings.

Atomic Subchart Symbol ScopeMain Chart Symbol Scope
InputInput, Output, Local, Parameter
OutputOutput, Local
ParameterParameter
Data Store MemoryData Store Memory, Local
Input EventInput Event

When you map data store memory in an atomic subchart to local data of enumerated type, you have two options for specifying the initial value of the data store memory:

  • In the Data Properties dialog box, set the Initial value field for the chart-level local data.

  • To apply the default value of the enumerated type, leave the Initial value field empty.

Map Input and Output Data for an Atomic Subchart

This model contains two Sine Wave blocks that supply input signals to a chart.

The chart consists of two linked atomic subcharts from the same library.

Both atomic subcharts contain these objects.

If you simulate the model, the output for y2 is zero.

Because the symbols in atomic subchart A have the same name as the symbols u1 and y1 in the main chart, they map to the correct variables. The symbols in atomic subchart B do not map to the correct variables u2 and y2 in the main chart, so you must edit the mapping.

  1. Right-click subchart B and select Subchart Mappings.

  2. Under Input Mapping, specify the main chart symbol for u1 to be u2.

  3. Under Output Mapping, specify the main chart symbol for y1 to be y2.

  4. Click OK.

When you run the model again, you get these results.

Map Atomic Subchart Variables to Bus Elements

This model contains two Sine Wave blocks that supply signals through a bus to a chart.

The chart consists of two linked atomic subcharts from the same library. Both atomic subcharts contain these objects.

If you simulate the model, you get an error because, in each subchart, the input u1 does not map to any variable in the main chart. To edit the mapping for u1 in each subchart:

  1. Right-click subchart A and select Subchart Mappings.

  2. Under Input Mapping, specify the main chart symbol for u1 to be the first element in the bus: BusIn.u1.

  3. Click OK.

  4. Repeat for subchart B, specifying the main chart symbol for u1 to be the second element in the bus: BusIn.u2.

When you run the model again, you get these results.

Map Atomic Subchart Variables to Elements of Matrix

When referring to elements of a vector or matrix, regardless of the action language of the chart, use:

  • One-based indexing delimited by parentheses and commas. For example, A(4,5).

  • Zero-based indexing delimited by brackets. For example, A[3][4].

Indices can be numbers or parameters in the chart. Use of other expressions as indices is not supported.

For example, this model contains two Sine Wave blocks that supply signals through a diagonal matrix to a chart.

The chart consists of two linked atomic subcharts from the same library. Both atomic subcharts contain these objects.

If you simulate the model, you get an error because, in each subchart, the input u1 does not map to any variable in the main chart. To edit the mapping for u1 in each subchart:

  1. Right-click subchart A and select Subchart Mappings.

  2. Under Input Mapping, specify the main chart symbol for u1 to be the top-left element in the matrix. For example, using zero-based indexing: M[0][0].

  3. Click OK.

  4. Repeat for subchart B, specifying the main chart symbol for u1 to be the bottom-right element in the matrix. For example, using one-based indexing: M(2,2).

When you run the model again, you get these results.

Map Atomic Subchart Parameters to Expressions

For atomic subcharts parameters, you can enter a constant expression or an expression that depends on one or more parameters in the main chart.

For example, this model contains two Sine Wave blocks that supply input signals to a chart.

The chart consists of two linked atomic subchart from the same library. Both atomic subcharts contain these objects.

If you simulate the model, you get an error because the parameter T is undefined. To fix this error, specify an expression for T to evaluate in the mask workspace of the main chart:

  1. Right-click subchart A and select Subchart Mappings.

  2. Under Parameter Mapping, as the value for T, enter -1.

  3. Click OK.

  4. Repeat for subchart B, specifying the value of T as 2.

When you run the model again, you get these results.

Map Input Events for an Atomic Subchart

The sf_yoyo model contains a Mux block that supplies input events to a chart.

The chart contains two superstates: Active and Inactive. The Active state uses input events to guard transitions between different substates.

To convert the Active state to an atomic subchart:

  1. Right-click the Active state and select Group & Subchart > Atomic Subchart.

  2. Right-click the atomic subchart and select Subchart Mappings.

    Under Input Event Mapping, each atomic subchart symbol maps to the correct input event in the main chart.

    The default mappings also follow the rules of using input events in atomic subcharts. For more information, see Rules for Using Atomic Subcharts

  3. Click OK.

Disable Input Events for Atomic Subcharts

To use an instance of a library chart as an atomic subchart, but not the entire saved set of input events, you can disable input events.

  1. Right-click the atomic subchart and select Subchart Mappings.

  2. To disable an input event, under Input Event Mapping, select <disabled> in the Main chart symbol drop-down list.

  3. Click OK.

Related Topics