Main Content

cv.cvdatagroup Class

Namespace: cv

Collection of cvdata objects


Objects of the cv.cvdatagroup class contain one or more cvdata objects. Each cvdata object contains coverage results for a model in the model hierarchy. A cv.cvdatagroup cannot contain multiple cvdata objects that have the same model name, simulation mode, and release.

Simulink® Coverage™ creates a cv.cvdatagroup object when you simulate a model containing model references when coverage is enabled, or if your model uses external code files and you selected external files for coverage analysis. Use the get and getAll class methods to retrieve coverage data for specific models in your model reference hierarchy. Use the allNames method to retrieve the cvdata object names to use with the get class method.

The cv.cvdatagroup class is a handle class.




cvdg = cv.cvdatagroup(cvdo1,cvdo2,...) creates a cvdatagroup object that contains the specified cvdata objects.


If you create a cv.cvdatagroup object by using multiple cvdata objects that have the same model name, simulation mode, and release, the resulting cv.cvdatagroup object contains only one of the cvdata objects.

Input Arguments

expand all

Coverage data, specified as one or more cvdata objects.

Data Types: cvdata


expand all

Object name, specified as a character array.

Example: = 'myDataGroup';



Data Types: char


expand all


collapse all

This example shows how to retrieve a specified coverage data object, all coverage data objects, or all coverage data object names from a cv.cvdatagroup object.

Load the example model.

modelName = 'slvnvdemo_eml_model_coverage_demo';

Use the Simulink.SimulationInput class to set up the simulation scenario with coverage enabled.

simIn = Simulink.SimulationInput(modelName);
simIn = setModelParameter(simIn,'CovEnable','on');
simIn = setModelParameter(simIn,'CovMetricStructuralLevel','MCDC');
simIn = setModelParameter(simIn,'CovSaveSingleToWorkspaceVar','on');
simIn = setModelParameter(simIn,'CovSaveName','covData');
simIn = setModelParameter(simIn,'CovSaveOutputData','off');

Simulate the model by passing the SimulationInput object to the sim function, and then retrieve the coverage data from the SimulationOutput object.

simOut = sim(simIn);
covData = simOut.covData
covData = ... cv.cvdatagroup

  slcoverageExternalFile (simulation mode: Normal)
  slvnvdemo_eml_model_coverage_demo (simulation mode: Normal)

The example model contains a MATLAB® Function block that calls an external MATLAB function. Because Simulink Coverage returns the coverage data for the MATLAB function in a separate cvdata object, sim returns a cv.cvdatagroup object that contains the coverage results for both the model and the MATLAB function.

To determine the name associated with each cvdata object inside the cv.cvdatagroup, use the class method allNames.

covDataNames = allNames(covData)
covDataNames =

  2x1 cell array

    {'slcoverageExternalFile'           }

The cv.cvdatagroup contains the coverage results for the model as well as the MATLAB function.

To retrieve the coverage data for the model, use the get class method.

modelCovData = get(covData,modelName)
modelCovData = ... cvdata
            version: (R2024a)
                 id: 882
               type: TEST_DATA
               test: cvtest object
             rootID: 884
           checksum: [1x1 struct]
          modelinfo: [1x1 struct]
          startTime: 07-Mar-2024 18:10:15
           stopTime: 07-Mar-2024 18:10:15
simulationStartTime: 0
 simulationStopTime: 1
            simMode: Normal

To retrieve coverage data for both the model and the external file, use the getAll class method.

covDataArray = getAll(covData)
covDataArray =

  2x1 cell array

    {1x1 cvdata}
    {1x1 cvdata}

This example shows how to create a cvdatagroup object using two cvdata objects.

Record coverage for slvnvdemo_cv_small_controller.

model_1 = 'slvnvdemo_cv_small_controller';
cvdo1 = cvsim(model_1);

Record coverage for slvnvdemo_powerwindow_controller.

model_2 = 'slvnvdemo_powerwindow_controller';
cvdo2 = cvsim(model_2);

Create a cv.cvdatagroup object that contains two cvdata objects.

cvdg = cv.cvdatagroup(cvdo1,cvdo2);

Version History

Introduced in R2007b