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 Metrics Dashboard tool to enable subsystem reuse 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. They can have different parameter settings and values. To replace clones with links to library blocks, from the 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 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.

  5. 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. 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. 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. Close the Metrics Dashboard and then open it again.

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

  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