Main Content

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

createSimulationInput

创建仿真输入对象

自 R2021a 起

语法

inputObj = createSimulationInput(testCasemodel)
inputObj = createSimulationInput(testcase,model,'WithHarness',harness)

说明

inputObj = createSimulationInput(testCasemodel) 为指定的 testCasemodel 创建 Simulink.SimulationInputsltest.harness.SimulationInput 对象。如果模型未加载,createSimulationInput 会在仿真时使用 testCase.loadSystem 来加载模型。

inputObj = createSimulationInput(testcase,model,'WithHarness',harness) 为指定的测试框架创建一个 sltest.harness.SimulationInput 对象。

输入参数

全部展开

测试用例的实例,指定为 sltest.TestCase 对象。

模型名称,指定为字符串或字符向量,不带模型扩展名。例如,对于 myModel.slx 模型,仅输入 myModel

示例: 'RollAutopilotModelRef'

框架的名称,指定为以逗号分隔的对,由 'WithHarness' 和要为其创建输入的测试框架的名称组成,指定为字符串或字符向量。

示例: 'WithHarness','RollAutopilotModelRef_harness1'

输出参量

全部展开

仿真输入对象,作为 Simulink.SimulationInputsltest.harness.SimulationInput 对象返回。要将仿真输入与测试框架一起使用,请使用 WithHarness 语法返回 sltest.harness.SimulationInput 对象。如果不使用 WithHarness 选项,此函数将返回 Simulink.SimulationInput。您可以使用这些对象分别将输入传递到框架或模型。

属性

Accesspublic
Sealedtrue

要了解方法的属性,请参阅方法属性

示例

全部展开

创建一个名为 testSim.m 的基于 MATLAB® 的 Simulink® 测试文件。

在该文件中,在 testOne 函数中定义测试用例。该函数为名为 myExample_harness1 的框架创建仿真输入,使用该输入进行仿真,并将仿真输出与基线文件进行比较。

classdef testSim < sltest.TestCase
    methods (Test)
        function testOne(testCase)
            in = testCase.createSimulationInput('myExample',...
               'WithHarness','myExample_Harness1');
            simOut = testCase.simulate(in);
            testCase.verifySignalsMatch(simOut,'myExampleBaseline.mat');
        end
    end 
end

版本历史记录

在 R2021a 中推出