Main Content

Detect Clones Programmatically on Multiple Models Across Different Folders

This example shows how to programmatically detect clones across multiple models located in different folders. For more information about the clone detection APIs, see Detect and Replace Subsystem Clones Programmatically.

This example demonstrates how to use the clone detection APIs to identify clones in six Simulink® models present in a folder. Replacement of clones is not possible using this example workflow. To replace clones programmatically in multiple models, see Detect and Replace Clones Programmatically in a Loop on Multiple Models.

1. At the MATLAB® command line, enter:


Save the models to a writeable folder.

2. Use the Simulink.CloneDetection.Settings class to create an object.

    cloneDetectionSettings = Simulink.CloneDetection.Settings();

3. Add the path of the folder with the models to the cloneDetectionSettings object.

    cloneDetectionSettings.Folders = {'D:\models'}

4. To find clones, execute the function Simulink.CloneDetection.findClones using the cloneDetectionSettings object.

    cloneResults = Simulink.CloneDetection.findClones(cloneDetectionSettings)

The cloneResults is an object of Simulink.CloneDetection.Results class which has two properties, Clones and ExceptionLog.

5. View the Clones.Summary field.


In this example, the models have four different clone groups with matching subsystem patterns, eighteen similar clones, and eight exact clones, and the twenty-six subsystem clones.

5. View the details of first clone group.


6. View the summary of first clone group.


7. View the clone list of the first clone group.


Similarly, you can find the results of other clone groups using the above steps.

Related Topics