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.
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 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 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:
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.
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.
> symbol next to
Group 1 to see all of the
subsystems that are exact clones and the number of blocks per clone.
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.