%% View Condition Coverage Data
% This example shows how to view condition coverage for a block in your
% model.

% Copyright 2021 The MathWorks, Inc.

%%
% Load the model.

modelName = 'slvnvdemo_cv_small_controller';
load_system(modelName);

%%
% Configure the coverage settings for the model by using a
% |Simulink.SimulationInput| object.

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

%%
% Simulate the model by passing |simIn| as the input to |sim|.

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

%%
% View the condition coverage results for the Logic block in the Gain
% subsystem by calling |conditioninfo| with the block path.

condCov = conditioninfo(covData,[modelName,'/Gain/Logic'])

%%
% |conditioninfo| returns an array with two scalars. The first value is the
% number of satisfied condition outcomes, and the second value is the
% number of total condition outcomes. Use these to determine the percentage
% of satisfied condition outcomes for the Logic block.

percentCondCov = 100 * condCov(1) / condCov(2)