Main Content

getSimulationPlots

Class: sltest.testmanager.TestIterationResult
Namespace: sltest.testmanager

Get plots from callbacks

Syntax

figs = getSimulationPlots(result)
figs = getSimulationPlots(result,index)

Description

figs = getSimulationPlots(result) returns figure handles of plots generated from the callbacks of the test iteration associated with the results. Figures returned using this method are not visible. To see the plots, set the figure handle Visible property to 'on'.

figs = getSimulationPlots(result,index) returns the figure handles from the simulation specified by index.

Input Arguments

expand all

Test case iteration result to get callback figure handles from, specified as an sltest.testmanager.TestIterationResult object or a simulation index of the result.

Simulation index, specified as 1 or 2.

Output Arguments

expand all

Figures from test case callbacks for the specified iteration, returned as an array of figure handles.

Examples

expand all

% Open the model for this example
openExample('sldemo_absbrake');

% Create the test file, suite, and case
tf = sltest.testmanager.TestFile...
   ('Simulation Plots for Test Iterations');
ts = createTestSuite(tf,'Sim Plots Test Suite');
tc = createTestCase(ts,'baseline','Sim Plots Test Case');

% Remove the default test suite
tsDel = getTestSuiteByName(tf,'New Test Suite 1');
remove(tsDel);

% Create a plot in a callback
setProperty(tc,'PostloadCallback',...
   'a = [1,2,3]; f = figure; plot(a);');

% Set option to save figures
opt = getOptions(tf);
opt.SaveFigures = true;

% Assign the system under test to the test case
setProperty(tc,'Model','sldemo_absbrake');

% Define iterations
vars = 32 : 0.5 : 34;

for k = 1 : length(vars)

    % Create test iteration object
    testItr = sltest.testmanager.TestIteration;

    % Set the parameter value for this iteration
    setVariable(testItr,'Name','g','Source',...
       'base workspace','Value',vars(k));

    str = sprintf('Iteration %d',k);

    % Add the iteration object to the test case
    addIteration(tc,testItr,str);
end

% Run the test and capture results
resultset = run(tf);
tfr = getTestFileResults(resultset);
tsr = getTestSuiteResults(tfr);
tcr = getTestCaseResults(tsr);
tir = getIterationResults(tcr);

% Get the callback plot figure handles from the first iteration
figs = tir(1).getSimulationPlots;

Version History

Introduced in R2017a