| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → Simulink Verification and Validation |
| Contents | Index |
| Learn more about Simulink Verification and Validation |
| On this page… |
|---|
Using Simulink software, you can include one model in another with Model blocks. Each Model block represents a reference to another model, called a referenced model or submodel. A referenced model can contain Model blocks that reference other models. You can construct a hierarchy of referenced models, in which the topmost model is called the top model. For more information, see Referencing a Model in the Simulink User's Guide.
Model coverage supports referenced models that operate in Normal mode. You can record coverage only for those Model blocks whose Simulation mode parameter specifies Normal. You can use model coverage commands to record coverage for referenced models (see Using Model Coverage Commands). However, if you want to record different types of coverage for models in a hierarchy, you must use the cvsimref function. The following steps describe a basic workflow for using this function to obtain model coverage results for Model blocks.
| Step | Description | See... |
|---|---|---|
| 1 | Use cv.cvtestgroup to group together test specification objects that correspond to each model in a hierarchy. | |
| 2 | Use cvsimref to simulate the top model in a hierarchy and record coverage results for its referenced models. | |
| 3 | Use cv.cvdatagroup to extract the coverage data objects that correspond to each model in a hierarchy. |
The next sections illustrate how to complete each of these steps using the following model hierarchy.

The cvtest command creates a test specification object for a Simulink model (see Creating Tests with cvtest). If your model references other models, you might use a different test specification object for each model in the hierarchy. In this case, the cv.cvtestgroup object allows you to group together multiple test specification objects. After you create a group of test specification objects, you simulate it using the cvsimref function.
For example, suppose that you create a different test specification object for each of the models in your hierarchy:
cvto1 = cvtest('TopModel')
cvto2 = cvtest('SubModel1')
cvto3 = cvtest('SubModel2')The following command creates a test group object named cvtg, which contains all the cvtest objects associated with your model hierarchy:
cvtg = cv.cvtestgroup(cvto1, cvto2, cvto3)
A cv.cvtestgroup object provides methods, such as add and get, so that you can customize the contents of the cv.cvtestgroup object to meet your needs. For more information, see the documentation for the cv.cvtestgroup function.
Once you create a test group object, you simulate it with the cvsimref function.
The call to cvsimref has the following default syntax:
cvdg = cvsimref(topModelName, cvtg)
This command executes the test group object cvtg by simulating the top model in the corresponding model hierarchy, topModelName. It returns the coverage results in a cv.cvdatagroup object named cvdg.
You can use parameters from the Simulink sim function in a cvsimref command to control the simulation:
To return the simulation time vector t, matrix of state values x, and matrix of output values y:
[cvdg,t,x,y] = cvsimref(topModelName, cvtg)
To override default simulation values with new values:
[cvdg,t,x,y] = cvsimref(topModelName, cvtg, timespan, options)
For descriptions of the parameters t, x, y, timespan, and options, see the documentation for the sim function.
Once you simulate a test group with cvsimref, the function returns results that reside in a cv.cvdatagroup object. The data group object contains multiple cvdata objects, each of which corresponds to coverage results for a particular model in the hierarchy.
A cv.cvdatagroup object provides methods, such as allNames and get, so that you can extract individual cvdata objects. For example, enter the following command to obtain a cell array that lists all model names associated with the data group cvdg:
modelNames = cvdg.allNames
To extract the cvdata objects that correspond to the particular models, enter:
cvdo1 = cvdg.get('TopModel')
cvdo2 = cvdg.get('SubModel1')
cvdo3 = cvdg.get('SubModel2')After you extract the individual cvdata objects, you can use other model coverage commands to use the coverage data of a particular model. For example, you can use the cvhtml function to create and display an HTML report of the coverage results (see Creating HTML Reports with cvhtml).
![]() | Coverage Script Example | Customizing the Model Advisor | ![]() |

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.
| © 1984-2010- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |