Main Content

Map Variables for Atomic Subcharts and Boxes

An atomic subchart is a graphical object that helps you create reusable subcomponents in a Stateflow® chart. An atomic box is a graphical object that helps you share graphical, truth table, MATLAB®, and Simulink® functions across several charts. Atomic subcharts and boxes are supported only in Stateflow charts in Simulink models. For more information, see Create Reusable Subcomponents by Using Atomic Subcharts and Reuse Functions by Using Atomic Boxes.

To ensure that each symbol in your atomic subchart or box accesses the correct symbol in the main chart, edit the mapping of subchart symbols. Right-click the subchart or box and select Subchart Mappings. In the Mappings tab of the properties dialog box, use the Main chart symbol drop-down list to specify which symbol in the main chart corresponds to each symbol in the subchart. Alternatively, you can type an expression specifying:

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

You can map a symbol 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 saturator logic to convert an input sine wave to an output square wave of the same frequency.

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 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 saturator logic to convert an input sine wave to an output square wave of the same frequency.

If you simulate the model, you get an error because the u1 inputs in each subchart do not map to any variables 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 the Elements of a 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. The 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 saturator logic to convert an input sine wave to an output square wave of the same frequency.

If you simulate the model, you get an error because the u1 inputs in each subchart do not map to any variables 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. The zero-based indexing format for this element is 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. The one-based indexing format for this element is M(2,2).

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

Map Atomic Subchart Parameters to Expressions

For parameters in an atomic subchart, you can specify an expression that combines constants, variables in the base workspace, and 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 saturator logic to convert an input sine wave to an output square wave of the same frequency.

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 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

This 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.

  3. Under Input Event Mapping, map each atomic subchart symbol to the corresponding input event in the main chart.

  4. Click OK.

Disable Input Events for Atomic Subcharts

Not every input event in an atomic subchart has to correspond to an event in the main chart. For example, you can create a linked atomic subchart that does not use the entire set of events that are defined in the library chart. To disable an input event in an atomic subchart:

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

  2. Under Input Event Mapping, in the Main chart symbol drop-down list, select <disabled>.

  3. Click OK.

Related Topics