Main Content

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

Open model ex_clone_detection.

open_system('ex_clone_detection.slx')

  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 Dashboard, 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. Open the Clone Detector app by clicking Open Conversion Tool. The Clone Detector app opens. For more information on the app, see Enable Component Reuse by Using Clone Detection.

  2. 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 Clone Results tab. The library is on the MATLAB® path. It has a default name of newLibraryFile.

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