You can use the Metrics Dashboard tool to help you reuse subsystems by identifying clones across a model hierarchy. Clones are identical MATLAB Function blocks, identical Stateflow charts, and subsystems that have identical block types and connections. The clones can have different parameter settings and values. To replace clones with links to library blocks, from the Metrics Dashboard, you can open the Clone Detector app.
To open the example model
ex_clone_detection, change your directory to the
matlabroot\help\toolbox\simulink\examples folder. At the MATLAB command line, enter:
ex_clone_detection.slx model to a local working folder.
On the Apps tab, click Metrics Dashboard.
In the Metrics Dashboard, click All Metrics.
In the Architecture section, the yellow bar in the Potential Reuse row indicates that the model contains clones. The percentage is the fraction of the total number of subsystems, including Stateflow Charts and MATLAB Function blocks, that are clones. To see details, click the yellow bar.
The model contains three clone groups.
SS4 are part of clone group one.
SS5 are part of clone group two.
SS7 are part of clone group three.
To replace clones with links to library blocks, open the Clone Detector app by clicking Open Conversion Tool. The Clone Detection app opens. For more information on the app, see Enable Component Reuse by Using Clone Detection.
Click Find Clones. The app contains a list of clone groups on the Clone Detection Actions and Results pane, on the Map Clone Groups to Library tab.
Click Replace Clones. The Clone Detector app replaces the clones with links to library blocks. The library blocks are in the library specified by the Library to place clones parameter. This parameter is on the Map Clone Groups to Library tab. The library is on the MATLAB path. It has a default name of
After you refactor, you can remove the latest changes from the model. In the Clone Detection Actions and Results pane, in the Logs tab, open the latest log and click Restore. Each time you refactor a model, the tool creates a backup model in the folder named with the prefix
m2m_ plus the model name.
If you have a Simulink Test license, you can verify the equivalency of the refactored model and the original model. Click Check Equivalency.
Navigate to the Metrics Dashboard.
Click All Metrics.
In the Architecture section, the blue bar in the Actual Reuse row indicates that 75% of model components are links to library subsystems. The Potential Reuse row indicates that the model does not contain any clones that do not have links to library blocks.