Documentation

Refactor Model with Clone Detection and Model Transformer Tools

With Simulink® Check™, you can use the Model Transformer and Identify Modeling Clones tools to refactor a model to improve model componentization and enable reuse.

Identify and Replace Clones with Links to Library Blocks

You can use the Identify Modeling Clones tool to enable component reuse by completing these tasks:

  • Identify subsystem clones.

  • Create library blocks from clones.

  • Create a model that replaces clones with links to library blocks.

  • Identify similar clones.

  1. Open the example model ex_clone_detection and the corresponding library ex_clone_library. Save the model and library to the current folder on the MATLAB path.

  2. In the Simulink Editor, from the Analysis menu, select Refactor Model > Identify Modeling Clones. To open the Identify Modeling Clones tool programmatically, at the MATLAB command prompt type: clonedetection('ex_clone_detection').

  3. Open the Identify Modeling Clones folder.

  4. Select Identify library clones and replace them with links to library blocks. In the Library file name field, insert the library name, ex_clone_library.

  5. Select Identify similar library clones. In the Library file name field, insert the library name, ex_clone_library.

  6. Select Identify Modeling Clones folder. Then, click Run Selected Checks. Because every check is selected by default, the tool identifies all possible clones in the model.

  7. Select each check. The checks contain hyperlinks to the clones in the model.

Note

Each check in the Identify Exact Clones folder contains a Refactor Model button. To replace clones with links to library blocks, you must complete each check and click Refactor Model. You cannot simultaneously run selected checks and refactor the model.

Replace Qualifying Modeling Patterns with Variant Blocks

To improve model componentization by replacing qualifying modeling patterns with Variant Source and Variant Subsystem blocks, use the Model Transformer tool.

The ex_variants_transformer model contains several modeling patterns that qualify for transformation into variants blocks.

  1. Open the example model ex_variants_transformer.

  2. Save the model to your working folder.

  3. From the Simulink Editor, open the Model Transformer tool by selecting Refactor Model > Model Transformer. Or, in the Command Window, type:

    mdltransformer(‘ex_variants_transformer’)

  4. Select the Model Transformer folder. To run selected steps, click the Run Selected Checks button. The tool identifies qualifying modeling patterns and creates a model containing Variant blocks.

  5. Click Run Selected Checks.

  6. Your working folder contains a folder called m2m_ex_variants_transformer. This folder contains the transformed model gen0_ex_variants_transformer.

  7. Click the Convert blocks to variants folder.

  8. The Results section contains hyperlinks to the original and transformed models.

Related Topics

Was this topic helpful?