Main Content

getSimulationPlots

Class: sltest.testmanager.TestCaseResult
Namespace: sltest.testmanager

Get plots from test case 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 case 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 results to get simulation plot figure handles from, specified as an sltest.testmanager.TestCaseResult object.

Simulation index, specified as 1 or 2.

Output Arguments

expand all

Figures from test case callbacks, returned as an array of figure handles.

Examples

Get Figure Handles and Generate Plots from Test Case Results

Get figure handles.

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

% Create the test file, suite, and case
tf = sltest.testmanager.TestFile('Simulation Plots Test Case');
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 test case 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');

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

% Get the test case callback plots figure handles
figs = tcr.getSimulationPlots;

Plot the figures.

  1. Add callbackfn(sltest_simout) to the test case cleanup callback.

    setProperty(tc,'CleanupCallback','callbackfn(sltest_simout)');

  2. Create the simout function in a MATLAB® file named simout.m. The function gets the first signal from the simulation object, opens a figure, and plots time vs. data in that figure.

    function callbackfn(simout)
        sig1 = simout.logsout.get(1);
        figure;
        plot(sig1.Values.Time, sig1.Values.Data)
    end
    
  3. Use this code to view the simulation plots. The code runs the test case, gets the test case results and figures, and sets the first figure to be visible.

    rs = tc.run
    tcr = rs.getTestCaseResults
    figs = getSimulationPlots(tcr)
    figs(1).set('Visible','on')
    

Version History

Introduced in R2017a