Documentation Center

  • Trial Software
  • Product Updates

Map Variables for Atomic Subcharts

Why Map Variables for Atomic Subcharts?

Variables in an atomic subchart do not always map directly to variables in the main chart. To ensure that each variable in your atomic subchart maps to the correct variable in the main chart, you edit the mapping (or parameterize the link). For details, see:

How to Map Variables in an Atomic Subchart

Depending on the scope of data or events in an atomic subchart, you update different sections on the Mappings tab of the State properties dialog box.

For...Go to...And...

Input data

Input Mapping

Specify the chart input or output data that corresponds to each atomic subchart symbol.

Output data

Output Mapping

Data store memory

Data Store Memory Mapping

Specify the data store memory or chart-level local data that corresponds to each atomic subchart symbol.

Parameter data

Parameter Mapping

Enter an expression for evaluation in the mask workspace of the main chart.

Input event

Input Event Mapping

Specify the chart input event that corresponds to each atomic subchart symbol.

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 that appears.

  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 that appears.

  3. Under Data Store Memory Mapping, specify the main chart symbol for dsm to be local_for_atomic_subchart.

      Tip   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 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, 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 that appears.

    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.

    Note:   In this example, the mappings are trivial because each input event in the atomic subchart maps to an input event of the same name in the main chart. For an example of how to use nontrivial mapping of input events, see the sf_elevator model. A mapping is nontrivial when the variable in the atomic subchart maps to a variable with a different name in the main chart.

    At the MATLAB® command prompt, enter:

    sf_elevator

    In the Elevator System chart, the two linked atomic subcharts use nontrivial mapping of input events.

Was this topic helpful?