MATLAB: How to extract code coverage metrics from a code coverage report

Simulink Coverage

Can I get the summary data extracted from a code coverage report?
I need the data to use it in another report. Is there a way to get just the metrics from the report?

Best Answer

In order to achieve that you need to first create a test object.
>> testObj = cvtest(model);
Then you have to run code coverage on the model.
>> [cvdo,simOut] = cvsim(testObj);
Then you can get the coverage results by using the following functions:
>> blk_handle = get_param([model], 'Handle');
>> executionCoverage = executioninfo(cvdo, blk_handle);
>> conditionCoverage = conditioninfo(cvdo, blk_handle);
>> decisionCoverage = decisioninfo(cvdo, blk_handle);
>> mcdcCoverage = mcdcinfo(cvdo, blk_handle);
You can refer to the attached script which accomplishes the above workflow.
Please follow the documentation link below to automate additional coverage workflows: