Compare Code Mappings of Simulink Models - MATLAB & Simulink (original) (raw)

The Simulink® Comparison Tool is an interactive tool for identifying and comparing differences between Simulink models. You can use the tool to compare the code mappings of models. TheComparison Tool shows mapping differences under Code Mappings, organized by mapping type.

Each mapping type that is different between the models appears as a subtree underCode Mappings. The blocks that contain the differences in this mapping type appear within the type subtree (not necessarily as immediate descendents). For example, the comparison in this screenshot shows that there are differences in the mapping types Embedded Coder C - Data Interface and Simulink Coder C. The differences of the first type are in the Outport blockout_1, and the differences of the second type are in theInport block in_1.

Comparison Tool comparing two models. Under Code Mappings, the Inport block in_1 is selected in both models, and the Comparison Tools shows that they use different storage classes below.

Unsupported mapping types, which refer to mapping categories not fully recognized by the tool (and therefore not fully detailed), are also displayed underCode Mappings if they contain differences, but as empty labels. Blocks with differences in unsupported mapping types do not appear in the comparison tool.

Two models are compared in the Simulink Comparison Tool. The label AUTOSAR Classic under Code Mappings is selected but it is empty. The lower panes of the tool display both No details to show.

This table shows supported and unsupported mapping types.

Mapping Type Target Description Supported by Comparison Tool
Simulink Coder C GRT-based system target file (grt.tlc) with C language Supported
Embedded Coder C - Data Interface ERT-based system target file (ert.tlc) with C language and data interface configuration
Embedded Coder C - Service Interface ERT-based system target file (ert.tlc) with C language and service interface configuration
Embedded Coder C++ Class ERT-based system target file (ert.tlc) with C++ language Not supported
AUTOSAR Classic AUTOSAR Classic system target file (autosar.tlc) with C language
AUTOSAR Adaptive AUTOSAR Adaptive system target file (autosar_adaptive.tlc) with C++ language
DDS (Data Distribution Service) ERT-based system target file (ert.tlc) with C++ language

As with other types of blocks displayed in the Comparison Tool, when you select a block with mapping difference, the difference is shown in the lower panes of the tool.

Compare Model Mapping with Comparison Tool

This example shows how to use the Comparison Tool to compare the code mappings of two models. The two models, mapDiff1 and mapDiff2, are identical except for a few differences.

Store the names of the models in variables.

model_1 = "mapDiff1"; model_2 = "mapDiff2";

Model Description

The two models have identical structure: a root-level input port connected to a Bias block, which is connected to a root-level output port.

Models mapDiff1 and mapDiff2.

Each model has two predefined sets of code mapping configurations:

The models are identical, except for these differences:

Block Compared Element Type of Mapping Value in mapDiff1 Value in mapDiff2
Bias Bias parameter Not a mapping element 1 2
Root-level inport Storage class Simulink Coder C ImportedExtern ExportedGlobal
Root-level outport Storage class Embedded Coder C - Data Interface BitField Struct

Open Comparison Tool

Enter this command in the Command Window to open the Comparison Tool:

The left and right panes of the tool show the first and second models, respectively. Each model is displayed in the form of a structured tree. Identical blocks do not appear in the structured trees. Blocks with elements that are different in the models appear as leaves. To learn more about how to use the Comparison Tool, see Understand Simulink Model Comparison Changes.

Comparison Tool showing the structured trees of blocks with differing elements in models mapDiff1 and mapDiff2.

The Comparison Tool shows code mapping differences regardless of whether or not you have the appropriate license to use the displayed mapping types. For example, even if you do not have Embedded Coder™ license you are still able to see the differences in the Embedded Coder mappings elements.

Step Through Code Mapping Differences

Select the in_1 leaf in the Comparison Tool. The lower panes of the tool display the storage class values of the root-level inport of the models, ImportedExtern on the lower-left pane and ExportedGlobal on the lower-right pane.

Comparison tool showing code mapping differences in the root-level inports.

Select the out_1 leaf. The lower panes of the tool now display the storage class values of the root-level output port of the models, Bitfield on the lower-left pane and Struct on the lower-right pane.

Comparison tool showing code mapping differences in the root-level outports.

Observe Differences in Models

You can optionally open the models to see the differences in them while observing the differences in the Comparison Tool.

Note: To see mapping elements in the models themselves, you do need the appropriate licenses.

If the models are not open, open them by entering these:

open_system(model_1) open_system(model_2)

Select the add_constant leaf in the Comparison Tool. In the lower panes of the Comparison Tool you see the values of the Bias parameter of the Bias block, 1 on the lower-left pane and 2 on the lower-right pane. If Always Highlight is cleared, click Highlight Now to highlight the Bias block in the models. Note that the Bias block itself is highlighted, not the parameter that differs between the models (the Bias parameter in this case).

Comparison Tool comparing models mapDiff1 and mapDiff2. The Bias block is selected. Highlight Now and Always Highlighted are outlined in the toolstrip. The Bias block is highlighted in the Simulink editor for both models.

Observe Mapping Element Differences in Models

Similar to other differences shown in the Comparison Tool, when you select a block in the structured tree of the tool, the block itself is highlighted in the canvas of the compared models. For example, when you select the in_1 leaf in the Comparison Tool, the root-level Inport block is highlighted in the models. As before, the lower panes of the tool display the Storage Class values of the root-level Inport in_1 of the models, ImportedExtern on the lower-left pane and ExportedGlobal on the lower-right pane.

Comparison Tool comparing models mapDiff1 and mapDiff2. The in_1 Inport block is selected in the Comparison Tool. The in_1 block is highlighted in the Simulink editor for both models.

To see the actual difference (storage class in this case):

  1. Open the Code Mappings editor (see Open the Code Mappings Editor — C).
  2. Navigate to the Inports tab.
  3. Look at the Storage Class value of the (single) entry in the list.

The storage class is ImportedExtern in mapDiff1 and ExportedGlobal in mapDiff2.

Code Mappings editor of models mapDiff1 and mapDiff2 are open with the Inports tab selected.

Limitations

See Also

Comparison Tool | visdiff | Simulink.ID.getSID | Code Mappings Editor – C

Topics