Identify Modeling Clones with the Metrics Dashboard

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.

Identify Clones

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:

cd(fullfile(docroot, 'toolbox','simulink','examples'));

  1. Save the ex_clone_detection.slx model to a local working folder.

  2. On the Apps tab, click Metrics Dashboard.

  3. In the Metrics Dasbhoard, click All Metrics.

  4. 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. SS1 and SS4 are part of clone group one. SS3 and SS5 are part of clone group two. SS6 and SS7 are part of clone group three.

Replace Clones with Links to Library Blocks

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

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

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

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.

Run Model Metrics on the Refactored Model

  1. Navigate to the Metrics Dashboard.

  2. Click All Metrics.

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

Related Topics