%% View Decision Coverage Data
% This example shows how to view decision coverage data for a block in your
% model.

% Copyright 2020 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 = setModelParameter(simIn,'CovEnable','on');
simIn = setModelParameter(simIn,'CovMetricStructuralLevel','Decision');
simIn = setModelParameter(simIn,'CovSaveSingleToWorkspaceVar','on');
simIn = setModelParameter(simIn,'CovSaveName','covData');

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

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

%%
% View the decision coverage results for the Saturation block by calling
% |decisioninfo| with the block path.

blockPath = [modelName,'/Saturation'];
decisionCov = decisioninfo(covData,blockPath)

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

percentDecisionCov = 100 * decisionCov(1) / decisionCov(2)