主要内容

本页采用了机器翻译。点击此处可查看最新英文版本。

getSimulationPlots

类: sltest.testmanager.TestCaseResult
命名空间: sltest.testmanager

从测试用例回调中获取图

语法

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

说明

figs = getSimulationPlots(result) 返回与结果相关的测试用例的回调生成的图的图形句柄。使用此方法返回的数字不可见。要查看图,请将图形句柄 Visible 属性设置为 'on'

figs = getSimulationPlots(result,index) 返回由 index 指定的仿真的图形句柄。

输入参数

全部展开

测试用例结果获取仿真绘图图形句柄,指定为 sltest.testmanager.TestCaseResult 对象。

仿真索引,指定为 12

输出参量

全部展开

来自测试用例回调的图形,以图形句柄数组的形式返回。

示例

获取图形句柄并从测试用例结果生成图

获取图形句柄。

% 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;

绘制图形。

  1. callbackfn(sltest_simout) 添加到测试用例清理回调。

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

  2. 在名为 simout 的 MATLAB® 文件中创建 simout.m 函数。该函数从仿真对象获取第一个信号,打开一个图形,并在该图形中绘制时间与数据的关系。

    function callbackfn(simout)
        sig1 = simout.logsout.get(1);
        figure;
        plot(sig1.Values.Time, sig1.Values.Data)
    end
    
  3. 使用此代码查看仿真图。代码运行测试用例,获取测试用例结果和图形,并将第一个图形设置为可见。

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

版本历史记录

在 R2017a 中推出