MATLAB Examples

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.

Contents

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 Library 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 shaded bar.
  5. The model contains two exact graphical clones. To identify where these clones are in the model, expand the menu items under ex_clone_detection. The table contains the names of the individual clones, SS4 and SS1, and the group name, Clone Group1. Click the Clone Group1 hyperlinks. In the model, the clones contain highlighting.

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 Identify graphical clones and replace them with links to library blocks. 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 docid:slcheck_ug.bvdvcxp-1.
  3. In the Results table, the left column contains hyperlinks to subsystem clones. The right column lists whether the subsystem is virtual or atomic and provides the subsystem function packaging.
  4. Click Refactor Model. The Clone Detection tool creates a model containing links to the library blocks. The library blocks are in the library specified by the New library file name parameter.
  5. In the bottom Results table, click the hyperlinks to navigate to the blocks before and after clone replacement.

In the refactored model, SS1 and SS4 link to the new library subsystem. The library is on the MATLAB path. It has a default name of graphicalCloneLibFile. The refactored model is in a folder that has the prefix m2m_ plus the model name. The refactored model has the default prefix gen2_ plus the model name.

Run Model Metrics on Refactored Model

  1. Add the folder that has the prefix m2m_ plus the model name to the MATLAB path.
  2. For the model gen2_ex_clone_detection, 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 shaded green bar in the Library Reuse row indicates that the model contains links to library subsystems.