Main Content

Refactor Models to Improve Component Reuse

You can use the Metrics Dashboard to identify clones across a model hierarchy. Clones are identical MATLAB Function blocks, identical Stateflow® charts, and subsystems that have identical block types and connections. Clones can have different parameter settings and values. To replace clones with links to library blocks, you can open the Clone Detector app from the Metrics Dashboard.

Use the Clone Detector app to refactor a model, improve model componentization and readability, and reuse components within a model. In this example, you launch the Clone Detector from the Metrics Dashboard. However, you can also open it by opening the Apps tab and clicking Clone Detector.

Identify and Replace Clones with Links to Library Blocks

  1. In the Architecture section, the blue bar in the Actual Reuse widget indicates the fraction of total number of subcomponents that are linked library blocks. Pause over the Actual Reuse widget to see more information. For this model, 10% of the total number of subcomponents are linked library blocks.

  2. To see more details, click the blue bar. System Lag, Throttle Command, and CheckRange are linked library blocks.

    Table with details on the library linked component content metric results for the sldemo_fuelsys model and its subsystems, charts, and MATLAB Function blocks

  3. Return to the main dashboard page.

  4. In the Architecture section, the Potential Reuse bar indicates that the model contains clones. Pause over Potential Reuse. For this model, 7% of the subcomponents are clones.

  5. To see more details, click the yellow bar. Pressure.map_estimate and Throttle.throttle_estimate are clones of each other.

  6. To determine whether these clones are candidates for replacement with linked library blocks, click Open Conversion Tool.

    The Clone Detector app opens as a new tab in the model.

  7. In the Clone Detection Results and Actions pane, click the Clone Results tab.

    There is one clone group. The light blue shading indicates that these clones are similar clones and not exact clones. Similar clones have different parameter settings and values.

  8. Expand the clone group.

    This clone group consists of two subcharts.

    Clone Detector App showing Clone Detection Results and Actions for the clone group

  9. To determine parameter differences, in the Block Difference column, click View parameter difference.

    The subcharts in this clone group call Simulink® functions that differ only by the value of the breakpoints parameters in the Lookup Table blocks inside of them.

  10. In the Clone Results tab, for the Library to place clones parameter, use the Browse button to choose a library or specify a new library name. If you specify a new library name, the app creates the library.

  11. Save the model to your working folder and, in the Clone Detector tab, click Replace Clones. The app replaces similar clones with links to masked library subsystems, if possible.

    In the Logs tab, click the latest log.

    The log contains a message indicating that the clones cannot be replaced with linked library blocks because the data in the Simulink Functions can not be promoted to subchart data.

  12. Close the Metrics Dashboard and the model.

When the Clone Detector app refactors a model to replace clones with links to library blocks, the app creates a backup folder. The backup folder name has the prefix m2m_<model name>. If you have a Simulink Test™ license, you can verify the equivalency of the refactored and original models by clicking Check Equivalency in the Clone Detector tab.

Explore Other Options

This table contains a list of common tasks that you can address with Simulink Check™.


Simplify and debug complex models.

Highlight Functional Dependencies

Run Model Advisor checks for compliance with safety standards associated with High-Integrity System Modeling and MAB Control Algorithm Modeling guidelines.

Check Model Compliance by Using the Model Advisor
Write custom Model Advisor checks.Define Custom Model Advisor Checks
Create and deploy a custom Model Advisor configuration.Create and Deploy Model Advisor Custom Configuration and Use Model Advisor Configuration Editor to Customize Model Advisor

Learn more about how to use the Metrics Dashboard to collect and view metric data for quality assessment.

Collect and Explore Metric Data by Using Metrics Dashboard
Configure compliance metrics, add metric thresholds, and customize the Metrics Dashboard layout. Customize Metrics Dashboard Layout and Functionality

Use the Model Transformer tool and the Clone Detector app to refactor a model to improve model componentization and readability and enable reuse.

Transform Model to Variant System and Enable Component Reuse by Using Clone Detection
Learn more about how to use Simulink products to test models and code, check for design errors, check against standards, measure coverage, and validate the system.Verification and Validation