With Simulink® Check™, you can use the Model Transformer tool, and the Clone Detector app to refactor a model, improve model componentization and readability, and reuse components within a model.
You can use the Clone Detector app to find clones of components and identify opportunities to reuse them. With the Clone Detector, you can:
Identify subsystem clones.
Create library blocks from clones.
Create a model that replaces clones with links to library blocks.
To use the Clone Detector:
Open the example model
Save the model to the current folder on the MATLAB path.
On the Apps tab, click Clone
Detector. To open the Clone Detector app
programmatically, at the MATLAB command prompt type:
On the Clone Detector tab, click View and select Help, Results and Properties.
Click Find Clones.
The model contains three groups of clones. One group contains exact clones. Exact clones are highlighted in pink. The other two groups contain similar clones. These groups are highlighted in blue. Darker shades of blue indicate that the clones in those groups are more similar than clones in groups with lighter shades of blue.
In the Clone Detection Actions and Results pane, in the Map Clone Groups to Library tab, for the Library to place clones parameter, specify a library. If you specify a new library name, the app creates the library.
In the Clone Detector tab, click Replace Clones.
The refactored model contains links to the library blocks in the
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 app 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.
To improve model componentization by replacing qualifying modeling patterns with Variant Source and Variant Subsystem blocks, use the Model Transformer tool.
ex_variants_transformer model contains several modeling
patterns that qualify for transformation into variant blocks.
Open the example model
entering these commands at the MATLAB command line:
Save the model to your working folder.
On the Apps tab, open the Model Transformer tool by selecting Model Transformer. Or, in the Command Window, type:
Click Transform model to variant system.
Click Run This Check. In the Analysis section, the Result table contains a list of system constants that qualify to be part of condition expressions in Variant Source or Variant Subsystem blocks.
Click Refactor Model.
Your working folder contains a folder called
m2m_ex_variants_transformer. This folder contains the
In the Action section, the Results table contains hyperlinks to the original and transformed models.
The Eliminate data store blocks allows you to replace data stores with blocks that improve model readability by making data dependency explicit. For an example, see Improve Model Readability by Eliminating Local Data Store Blocks.
The Transform table lookup into prelookup and interpolation check allows you to replace Lookup Table blocks into a single shared Prelookup block and multiple Interpolation blocks. For an example, see Improve Efficiency of Simulation by Optimizing Prelookup Operation of Lookup Table Blocks.