%% Save Cumulative Coverage Data to a File
% This example shows how to save more than one coverage data object to a
% single coverage data file.

% Copyright 2020 The MathWorks, Inc.

%%
% Move the current MATLAB&reg; directory to the location that contains the
% example files.
%

openExample('slcoverage/SaveCumulativeCoverageDataToAFileExample')

%% Load the model
% First, load the model into memory.
%

modelName = 'slvnvdemo_ratelim_harness';
load_system(modelName);

%% Set model parameters for coverage
% Create a |Simulink.SimulationInput| object to set coverage parameters.

covSet = Simulink.SimulationInput(modelName);
covSet = covSet.setModelParameter('CovEnable','on');
covSet = covSet.setModelParameter('CovMetricStructuralLevel','MCDC');
covSet = covSet.setModelParameter('CovScope','Subsystem');
covSet = covSet.setModelParameter('CovPath','/Adjustable Rate Limiter');
covSet = covSet.setModelParameter('CovSaveSingleToWorkspaceVar','on');

%% Simulate the model to collect coverage data
% Load the data files and then simulate the model to collect two sets of
% coverage data.
%

load within_lim.mat
covSet = covSet.setModelParameter('CovSaveName','covData1');
simOut1 = sim(covSet);

%%
% Now simulate the model a second time using the second data file.
%

load rising_gain.mat
covSet = covSet.setModelParameter('CovSaveName','covData2');
simOut2 = sim(covSet);

%% Save the coverage data to a file
% Save the results in a cell array.
%

cov_results{1} = covData1;
cov_results{2} = covData2

%%
% Save the results to a file.
%

cvsave('ratelim_testdata',cov_results{:});
