Documentation

Map Variables for Atomic Subcharts

How to Map Variables in an Atomic Subchart

To ensure that each variable in your atomic subchart maps to the correct variable in the main chart, edit the mapping (or parameterize the link). In the State properties dialog box, select the Mappings tab on the State properties dialog box, and choose a mapping for each data and input event.

You can map a variable in the atomic subchart to a variable in the main chart with the same or different scope. These mappings are supported.

Atomic Subchart Variable ScopeMain Chart Variable Scope
InputInput, Output, Local, Parameter
OutputOutput, Local
Data Store MemoryData Store Memory, Local
ParameterParameter

You can map a variable in an atomic subchart to an element of a bus in the main chart.

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

  • Set the Initial value field for the chart-level local data in the Data properties dialog box.

  • Leave the Initial value field empty so that the default value of the enumerated type applies.

Map Input and Output Data for an Atomic Subchart

Suppose that you have a modelmodel with two Sine Wave blocks that supply input signals to a chart.

Your chart contains two linked atomic subcharts from the same library.

Both atomic subcharts contain the following objects.

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

Because atomic subchart B uses u1 and y1 instead of u2 and y2, you must edit the mapping:

  1. Right-click subchart B and select Properties.

  2. Click the Mappings tab in the dialog box.

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

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

  5. Click OK.

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

Map Data Store Memory for an Atomic Subchart

Suppose that you have a modelmodel with two Sine Wave blocks that supply input signals to a chart.

Your chart contains a linked atomic subchart from a library.

The linked atomic subchart contains the following objects.

If you simulate the model, you get an error because the data store memory, dsm, does not map to any variable in the main chart. To fix the mapping for dsm:

  1. Right-click subchart A and select Properties.

  2. Click the Mappings tab in the dialog box.

  3. Under Data Store Memory Mapping, specify the main chart symbol for dsm to be local_for_atomic_subchart. You can specify either data store memory or chart-level local data from the main chart. For chart-level local data, the First index property must be zero.

  4. Click OK.

When you run the model now, you get the following results.

Map Parameter Data for an Atomic Subchart

Suppose that you have a modelmodel with two Sine Wave blocks that supply input signals to a chart.

Your chart contains a linked atomic subchart from a library:

The linked atomic subchart contains the following 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 Properties.

  2. Click the Mappings tab in the dialog box that appears.

  3. Under Parameter Mapping, enter 0.2.

  4. Click OK.

When you run the model now, you get the following results.

Map Input Events for an Atomic Subchart

The sf_yoyosf_yoyo model contains a Mux block that supplies input events to a char.

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, follow these steps:

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

  2. Specify the mapping of input events for the atomic subchart.

    1. Right-click the atomic subchart and select Properties.

    2. Click the Mappings tab in the dialog box.

    3. Under Input Event Mapping, note that 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

    4. Click OK.

Was this topic helpful?