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.
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.
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 Actions and Results pane.
Properties. Select to view the Detected Clone Properties pane.
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
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
Click Find Clones to identify clones.
The color of subsystems
changes to red to indicate that they are exact clones.
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
Clone Group 1 is displayed.
> symbol next to
Group 1 to see all of the
subsystems that are exact clones and the number of blocks per clone.
In the Clone Detection Actions and Results 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
.slx files of the subsystem
references in your working folder.
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.
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.