getSimulationPlots
Class: sltest.testmanager.TestCaseResult
Namespace: sltest.testmanager
Get plots from test case callbacks
Syntax
figs = getSimulationPlots(result)
figs = getSimulationPlots(result,index)
Description
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 figs
= getSimulationPlots(result
)Visible
property
to 'on'
.
returns
the figure handles from the simulation specified by figs
= getSimulationPlots(result
,index
)index
.
Input Arguments
Output Arguments
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.
Add
callbackfn(sltest_simout)
to the test case cleanup callback.setProperty(tc,'CleanupCallback','callbackfn(sltest_simout)');
Create the
simout
function in a MATLAB® file namedsimout.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
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