Main Content

get

Class: cv.cvdatagroup
Namespace: cv

Get specified cvdata object in cvdatagroup

Description

covData = get(cvdg,dataName) returns one or more cvdata objects in the cv.cvdatagroup object cvdg that correspond to the model or file specified in dataName. get returns multiple cvdata objects if you simulate the same model reference with multiple different simulation modes.

covData = get(cvdg,dataName,simMode) returns the cvdata object or objects that have the simulation mode simMode.

Input Arguments

expand all

Coverage data group, specified as a cv.cvdatagroup object.

Data Types: cv.cvdatagroup

Name of coverage data, specified as a character array or string array. dataName can be the name of a model, subsystem, or external code file that corresponds to one or more cvdata objects contained in the cv.cvdatagroup. If the function does not find a match, it returns an empty array. If the function finds multiple matches, it returns a cell array of cvdata objects.

Data Types: char | string

Simulation mode that corresponds to one or more cvdata objects in the cv.cvdatagroup object, specified as one of the following:

Object SpecificationDescription

"Normal"

Model in normal simulation mode.

"SIL" or "PIL"

Model in software-in-the-loop (SIL) or processor-in-the-loop (PIL) simulation mode.

"ModelRefSIL" or "ModelRefPIL"

Model reference in software-in-the-loop (SIL) or processor-in-the-loop (PIL) simulation mode.

"ModelRefTopSIL" or "ModelRefTopPIL"

Model reference in software-in-the-loop (SIL) or processor-in-the-loop (PIL) simulation mode with the code interface set to the top model.

If the function does not find a match, it returns an empty array. If the function finds multiple matches, it returns a cell array.

Data Types: char | string

Output Arguments

expand all

Coverage data, returned as a cvdata object, or a cell array of cvdata objects. If you specified simMode, covDataArray only contains coverage data with the matching simMode.

Data Types: cell

Examples

expand 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';
load_system(modelName);

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'           }
    {'slvnvdemo_eml_model_coverage_demo'}

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: 12-Feb-2024 23:40:53
           stopTime: 12-Feb-2024 23:40:53
  intervalStartTime: 
   intervalStopTime: 
simulationStartTime: 0
 simulationStopTime: 1
             filter: 
            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}

Version History

Introduced in R2007b