Main Content

Identify Data Type Match with Library Clone Detection

This example shows how to programmatically detect clones and determine whether the inport data types of the library subsystem matches the inport data types of the clones in a model. For more information about Clone Detection APIs, see Detect and Replace Subsystem Clones Programmatically.

This example uses the model ex_clone_datatype and the library file lib_datatype to show how to determine the data type match between the library subsystem and the clone in the model.

Save the model and library file in the current working directory.

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

    cloneDetectionSettings = Simulink.CloneDetection.Settings();

2. Add the library file lib_datatype to the cloneDetectionSettings object.

    cloneDetectionSettings.Libraries = "lib_datatype"
cloneDetectionSettings = 

  Settings with properties:

                            IgnoreSignalName: 0
                         IgnoreBlockProperty: 0
                      ExcludeModelReferences: 0
                         ExcludeLibraryLinks: 0
                    ParamDifferenceThreshold: 50
    ReplaceExactClonesWithSubsystemReference: 0
                                   Libraries: {'/tmp/Bdoc24b_2725827_4174705/tp4e098cce/slcheck-ex23244177/lib_datatype.slx'}
                                     Folders: {}
                     DetectClonesAcrossModel: 0
                      ExcludeInactiveRegions: 0
                               DataTypeCheck: 0

3. Set DataTypeCheck to 1.

    cloneDetectionSettings.DataTypeCheck = 1
cloneDetectionSettings = 

  Settings with properties:

                            IgnoreSignalName: 0
                         IgnoreBlockProperty: 0
                      ExcludeModelReferences: 0
                         ExcludeLibraryLinks: 0
                    ParamDifferenceThreshold: 50
    ReplaceExactClonesWithSubsystemReference: 0
                                   Libraries: {'/tmp/Bdoc24b_2725827_4174705/tp4e098cce/slcheck-ex23244177/lib_datatype.slx'}
                                     Folders: {}
                     DetectClonesAcrossModel: 0
                      ExcludeInactiveRegions: 0
                               DataTypeCheck: 1

4. Execute the function Simulink.CloneDetection.findClones using the cloneDetectionSettings object.

    cloneResults = Simulink.CloneDetection.findClones('ex_clone_datatype',cloneDetectionSettings)
cloneResults = 

  Results with properties:

          Clones: [1x1 struct]
    ExceptionLog: {}

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

5. View the clone group.

    cloneResults.Clones.CloneGroups(1)
ans = 

  struct with fields:

         Name: 'lib_datatype/SS4'
      Summary: [1x1 struct]
    CloneList: {7x1 cell}

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

    cloneResults.Clones.CloneGroups(1).CloneList{1}
ans = 

  struct with fields:

             Name: 'Clone Region 1'
    PatternBlocks: {8x1 cell}
    DataTypeMatch: 0

CloneList is a structure with fields Name, PatternBlocks, and DataTypeMatch. The DataTypeMatch field is 0, which indicates that inport data types of the library subsystem does not match the inport data types of Clone Region 1.

Related Topics