Main Content

Replace Exact Clones with Subsystem Reference

Exact clones are modeling patterns that have identical block types, connections, and parameter values. The Clone Detector identifies these clones across referenced model boundaries. You can then reuse components by replacing exact clones with library links and Subsystem Reference blocks. To replace exact clones with library links, see Enable Component Reuse by Using Clone Detection. This example demonstrates how to replace subsystem clones with Create and Use Referenced Subsystems in Models blocks.

Identify Exact Clones

  1. Open the model ex_detect_clones.


    Simulink canvas for ex_detect_clones model

  2. Save the model to your working folder. The model must be open to access the app.

  3. On the Apps tab, click Clone Detector. Alternatively, on the MATLAB® command line enter:

  4. The app opens the Clone Detector tab. This example takes you through each section.

    Clone Detector toolstrip with sections for View, Prepare, Detect, Refactor, and Verify

Set Up Panes for Clone Detection

The app displays information on three panes. To open the panes, use the View menu. The panes are:

  • Help - Select to access a help pane that contains an overview of the clone detection workflow.

  • Results - Select to view the Clone Detection Results and Actions pane.

  • Properties - Select to view the Detected Clone Properties pane.

Set the Parameters for Clone Detection

You can set up the parameters for clone detection by using the Settings drop-down menu.

  • Select Replace Exact Clones with Subsystem References.

  • Click Exclude Components to access the Exclude model references, Exclude library Links, and Exclude inactive and commented out regions options. Enabling the Exclude inactive and commented out regions option, leads to exact clone SS1 not being identified because of Variant Source block in the model. For more information, see Exclude Components from Clone Detection. Keep the Exclude inactive and commented out regions option cleared.

  • Click Detect Clones Across Model to enable detect clones anywhere across the model. You can choose the values of Minimum Region Size and Minimum Clone Group Size to detect the clones with these matching blocks. Minimum Region Size is the number of blocks per clone and Minimum Clone Group Size is the number of clones present in that clone group. The default size for each is 2.

Identify Clones in the Model

  1. Click Find Clones to identify clones.

  2. The color of subsystems SS1 and SS4 changes to red to indicate that they are exact clones.

Analyze the Clone Detection Results

After identifying clones, you can analyze the results and make changes to the model as necessary. To analyze the results:

  1. In the Clone Detection Results and Actions panel, on the Clone Results tab, a clone group Exact Clone Group 1 is displayed.

  2. Click the > symbol next to Exact Clone Group 1 to see all of the subsystems that are exact clones and the number of blocks per clone.

  3. In the Clone Detection Results and Actions pane, click the Logs tab. Click the hyperlink on the Logs pane.

    The Clone Detection Report is generated in HTML and saved in the MATLAB current folder. The report opens in a new web browser window, showing a summary of clones, individual detection results with detailed information on clone groups, clone types, detection parameters, and exclusion configurations applied to the model.

  4. Click the Model Hierarchy tab and expand ex_detect_clones. Click the hyperlinks to highlight the subsystems that are present in the model.

  5. In the Detected Clone Properties pane, in the Refactor Benefits section, you can consider the percentage of exact clones present.

    Refactoring the model reduces 6.4516% of the model reuse.

    Refactor Benefits section showing potential reuse percentage

Replace Clones

  1. In the Clone Detector tab, click Replace Clones. The exact clones are replaced with Subsystem Reference blocks. You can see the .slx files of the subsystem references in your working folder.

  2. You can restore the model to its original configuration with clones by clicking the Restore button in the Clone Results tab of the Clone Detection Results and Actions pane.

Check the Equivalency of the Model

If you have a Simulink Test™, you can check equivalence of the new model is to the original model in the Clone Detection tab by clicking Check Equivalency.

Equivalency Check window with button to View Results

Related Topics