This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Enable Subsystem Reuse with Clone Detection

You can use the Model Metrics Dashboard tool to enable subsystem reuse by identifying exact graphical clones across a model hierarchy. Exact graphical clones are identical MATLAB Function blocks, identical Stateflow Charts, and subsystems that have identical block types, connections, and parameter settings and values. To replace clones with links to library blocks, from the Model Metrics Dashboard, you can open the Identify Modeling Clones tool.

Identify Exact Graphical Clones

To open the example model ex_clone_detection, change 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. In the Simulink Editor, from the Analysis menu, select Metrics Dashboard.

  3. On the toolstrip, click the All Metrics button.

  4. In the ARCHITECTURE section, the yellow shaded bar in the Potential Reuse row indicates that the model contains exact graphical clones. The percentage is the fraction of the total number of subsystems, including Stateflow Charts and MATLAB Function blocks, that are exact graphical clones. To see details, click the yellow bar.

  5. The model contains two exact graphical clones, SS4 and SS1.

Replace Exact Graphical Clones with Links to Library Blocks

  1. To replace clones with links to library blocks, open the Clone Detection tool by clicking Open Conversion Tool.

  2. The Clone Detection tool opens and reruns the analysis. The results are in the step Replace graphical clones with library links. The Model Metrics Dashboard tool identifies only exact graphical clones. The Clone Detection tool identifies other clone types and refactors a model to replace some of these clones with links to library blocks. For more information, see Enable Component Reuse by Using Clone Detection.

  3. The Results table contains hyperlinks to the subsystem clones.

  4. Click Refactor Model. The Clone Detection tool replaces the clones with links to library blocks. The library blocks are in the library specified by the New library file name parameter. The library is on the MATLAB path. It has a default name of graphicalCloneLibFile. The Refactor Model button is now unavailable, and the Undo button is enabled.

After you refactor, you can remove the latest changes from the model by clicking the Undo button. Each time you refactor a model, the tool creates a back-up model in the folder that has the prefix m2m_ plus the model name.

Run Model Metrics on Refactored Model

  1. Navigate back to the Metrics Dashboard.

  2. On the toolstrip, click the All Metrics button.

  3. In the ARCHITECTURE section, the blue bar in the Actual Reuse row indicates that 25% of model components are links to library subsystems. The Potential Reuse row indicates that the model does not contain any exact graphical clones that do not have links to library blocks.

Related Topics