动态系统仿真
使用参数名称-值对组对指定模型进行仿真。simOut
=
sim(model
,Name,Value
)
使用结构体 simOut
=
sim(model
,ParameterStruct
)ParameterStruct
中指定的参数值对指定模型进行仿真。
sim
命令行选项对模型进行仿真在绝对容差为 1e-5
的条件下以 Rapid Accelerator 模式对模型 vdp
进行仿真,并将状态保存在 xoutNew
中,将输出保存在 youtNew
中。
使用名称-值对组结构体 paramNameValStruct
为 sim
命令指定参数:
paramNameValStruct.SimulationMode = 'rapid'; paramNameValStruct.AbsTol = '1e-5'; paramNameValStruct.SaveState = 'on'; paramNameValStruct.StateSaveName = 'xoutNew'; paramNameValStruct.SaveOutput = 'on'; paramNameValStruct.OutputSaveName = 'youtNew'; simOut = sim('vdp',paramNameValStruct)
### Building the rapid accelerator target for model: vdp ### Successfully built the rapid accelerator target for model: vdp Build Summary Top model rapid accelerator targets built: Model Action Rebuild Reason ====================================================================================== vdp Code generated and compiled Code generation information file does not exist. 1 of 1 models built (0 models already up to date) Build duration: 0h 0m 13.692s
simOut = Simulink.SimulationOutput: xoutNew: [65x2 double] youtNew: [65x2 double] SimulationMetadata: [1x1 Simulink.SimulationMetadata] ErrorMessage: [0x0 char]
sim
命令行选项对模型进行仿真在绝对容差为 1e-5
的条件下以 Rapid Accelerator 模式对模型 vdp
进行仿真,并将状态保存在 xoutNew
中,将输出保存在 youtNew
中。
在配置集 mdl_cs
中为 sim
命令指定名称-值对组形式的参数:
mdl = 'vdp'; load_system(mdl) simMode = get_param(mdl, 'SimulationMode'); set_param(mdl, 'SimulationMode', 'rapid') cs = getActiveConfigSet(mdl); mdl_cs = cs.copy; set_param(mdl_cs,'AbsTol','1e-5',... 'SaveState','on','StateSaveName','xoutNew',... 'SaveOutput','on','OutputSaveName','youtNew') simOut = sim(mdl, mdl_cs);
### Building the rapid accelerator target for model: vdp ### Successfully built the rapid accelerator target for model: vdp Build Summary Top model rapid accelerator targets built: Model Action Rebuild Reason ====================================================================================== vdp Code generated and compiled Code generation information file does not exist. 1 of 1 models built (0 models already up to date) Build duration: 0h 0m 12.529s
set_param(mdl, 'SimulationMode', simMode)
使用默认模型配置参数对模型 vdp
进行仿真。
simOut = sim('vdp','ReturnWorkspaceOutputs','on')
使用 sim
命令指定的参数将覆盖 Model Configuration Parameters 对话框中定义的值。软件将在仿真结束时恢复原始配置值。
如果一个模型中包含 model reference 模块,参数设定将应用于顶层模型。
当仿真模型的停止时间为无限长时,要停止仿真,必须按 Ctrl+C。Ctrl+C 会中断仿真,并且仿真结果不会保存在 MATLAB 工作区中。
要指定仿真的时间跨度,必须指定 StartTime
和 StopTime
参数。
要记录模型时间、状态或输出,请使用 Model Configuration Parameters 对话框的 Data Import/Export 窗格。
要记录信号,请使用 To Workspace 或 Scope 等模块,或者使用 Viewers and Generators Manager 直接记录结果。
要获取模型 vdp
的仿真参数列表,请在 MATLAB 命令行窗口中输入:
configSet = getActiveConfigSet('vdp') configSetNames = get_param(configSet, 'ObjectParameters')
此命令列出多个对象参数,包括仿真参数,如 'StopTime'
、'SaveTime'
、'SaveState'
、'SaveOutput'
和 'SignalLogging'
。