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 Subsystem Reference blocks.
Identify Exact Clones
Open the model
ex_clone_detection. At the MATLAB® command line, enter:
Save the model to your working folder. The model must be open to access the app.
On the Apps tab, click Clone Detector. Alternatively, on the MATLAB command line enter:
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 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
SS1not 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. The default size is set to
Identify Clones in the Model
Click Find Clones to identify clones.
The color of subsystems
SS4changes 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:
In the Clone Detection Results and Actions panel, on the Clone Results tab, a clone group
Exact Clone Group 1is displayed.
>symbol next to
Exact Clone Group 1to see all of the subsystems that are exact clones and the number of blocks per clone.
In the Clone Detection Results and Actions pane, click the Logs tab. Click the hyperlink on the Logs pane.
A new window opens the clone detection results with an integrated report on the identified clones, the types of clones, the parameters of detection, and the exclusions in the clone detection.
Click the Model Hierarchy tab and expand
ex_clone_detection. Click the hyperlinks to highlight the subsystems that are present in the model.
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.
In the Clone Detector tab, click Replace Clones. The exact clones are replaced with Subsystem Reference blocks. You can see the
.slxfiles of the subsystem references in your working folder.
You can restore the model to its original configuration in the Clone Detection Results and Actions 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.