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 app 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 clones with Subsystem Reference blocks.

Identify Exact Clones

  1. Open the model ex_clone_detection. At the MATLAB® command line, enter:

    addpath(fullfile(docroot,'toolbox','simulink','examples'))
    ex_clone_detection

  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:

    clonedetection("ex_clone_detection")
  4. The app opens the Clone Detector tab. This example takes you through each section.

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 and Results 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 subsystems and referenced models from clone detection. Keep the Exclude inactive and commented out regions option cleared.

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. Open the Clone Detection Action and Results pane. On the Logs tab, click the hyperlink.

    A new window opens, that lists the clone detection results and shows an integrated report on the identified clones, the parameters of detection, and the exclusions in the clone detection.

  2. In the Clone Detection Action and Results pane, click the Map Clone Groups to Subsystem Reference tab.

    A clone group Exact Clone Group 1 is displayed.

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

  4. Click the Model Hierarchy tab and expand ex_clone_detection. 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.

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 in the Clone Detector Actions and Results pane. Open the Logs tab, click the hyperlink for the version you want to restore, and click Restore.

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.

Related Topics