使用 Simulink SimulationInput 对象作为 class 的 属性

Using a Simulink SimulationInput Object as a property of a class

我想设置一个 class 的对象,它包含一个 simulink 模型的所有变量作为它的属性。

为了以后能够使用并行仿真,我想在方法中有一个函数,它获取所有属性并将它们提供给 Simulink SimulationInput 对象(通过“setVariable”方法), 但是当我 运行 它时,setVariable 函数不会填充对象 'in' 的变量。

代码看起来有点像这样:

classdef SimSetup

properties
    mdl                        = 'SimulinkFile'
    SimulationTime             = 2
    Plant
    in
end

methods
    function this = SimSetup()
        open_system(this.mdl);
        this.Plant = load('PlantData.mat','xPlant');
    end

    function createSimIn(this)
        this.in = Simulink.SimulationInput(this.mdl);       
        this.in = this.in.setVariable('SimulationTime', this.SimulationTime);
    end
end

提前致谢

错误如下:

我要么必须使用句柄 class,要么必须 return 将函数的输出输出到对象本身(简而言之:function this = createSimIn(this))。