%% Retrieve Cyclomatic Complexity Data from Coverage Object
% This example shows how to retrieve cyclomatic complexity information for
% the Gain subsystem of the |slvnvdemo_cv_small_controller| model.

% Copyright 2020 The MathWorks, Inc.

%%
% Load the |slvnvdemo_cv_small_controller| model.
%

modelName = 'slvnvdemo_cv_small_controller';
load_system(modelName);

%%
% Create a test specification object and enable decision, condition, and
% MCDC coverage. Then, simulate the model using |cvsim|.
%

testObj = cvtest(modelName);
testObj.settings.decision = 1;
testObj.settings.condition = 1;
testObj.settings.mcdc = 1;
covData = cvsim(testObj);

%%
% Retrieve cyclomatic complexity information for the Gain subsystem.
%

gainPath = [modelName,'/Gain'];
gainComplexity = complexityinfo(covData,gainPath)

%%
% The Gain subsystem itself does not record cyclomatic complexity, but the
% contents of the subsystem do. This can be seen in the results because the
% total complexity is 1, which includes the subsystem and all of its
% descendants. In contrast, the local complexity is 0, indicating that the
% one point of complexity comes from one of the descendants, in this case a
% Switch block.
%

switchPath = [modelName,'/Gain/Switch'];
switchComplexity = complexityinfo(covData,switchPath)