Main Content

SIM

模拟a万博1manbetx模型

Description

模拟万博1manbetx®模型代表动态系统。模拟模型使您可以理解系统的行为,这是模拟时间的函数。这SIM命令使用指定的模型,并将参数应用于模型。在模拟结束时,SIM命令恢复其应用的任何参数。

模拟= sim(模型使用现有模型配置参数模拟指定的模型,并将结果返回为万博1manbetxsimulink.simulationOutput目的(single-output format).

在里面数据导入/导出pane of the配置参数对话框,单个仿真输出is selected by default. If the单个仿真输出未选择,仿真结果将作为时间向量返回。

要使用向后兼容格式(时间向量)返回模拟结果,请参见向后兼容语法

模拟= sim(模型,,,,名称,价值使用参数名称值对模拟指定的模型。

模拟= sim(SIM我n使用在万博1manbetxSimulink.SimulationInput目的SIM我n。这SIM命令可以与一个数组一起使用SimulationInput在系列中运行多个模拟的对象。如果SIM我n是一个数组万博1manbetxSimulink.SimulationInput对象,输出作为数组返回万博1manbetxsimulink.simulationOutput对象。

例子

模拟= sim(模型,,,,参数结构使用结构中指定的参数值模拟指定的模型参数结构

例子

模拟= sim(模型,,,,ConfigSetSIMulates the specified model using the configuration settings specified in the model configuration setConfigSet

Examples

全部收缩

此示例通过SimulationInput目的。

打开模型。

openExample('万博1manbetxsimulink_general/sldemo_househeatexample'

创建一个SimulationInput目的for this model.

mdl ='sldemo_househeat';in = Simulink.SimulationInput(mdl);

修改块参数。

in = in.setBlockParameter('sldemo_househeat/set Point',,,,'价值',,,,'300');

Simulate the model.

out = sim(in)

Simulate the model,vdp就像目前的状态一样,无论是未加载还是加载,并且具有一些未保存的更改。

On the Data Import/Export pane of the Configuration Parameters dialog box,单个仿真输出is selected by default, soSIM使用单输出格式(仿真对象)返回仿真结果。这种选择覆盖了数据集用于信号记录的格式。

simout = sim('vdp'

Simulate the model,vdp, 和save the states inXoutnew和输出Youtnew

使用名称值对结构指定参数paramNameValStructfor theSIM命令:

paramnamevalsstruct.savestate ='上';paramnamevalsstruct.statesavename ='xoutnew';paramNameValStruct.SaveOutput ='上';paramnamevalsstruct.outputsavename ='Youtnew';simout = sim('vdp',paramnamevalsstruct)
模拟= Simulink.SimulationOutput: xoutNew: [64x2 double] youtNew: [64x2 double] SimulationMetadata: [1x1 Simulink.SimulationMetadata] ErrorMessage: [0x0 char]

Simulate the model,vdp,,,,for an absolute tolerance of1e-5并保存美国Xoutnew和输出Youtnew

将参数指定为配置集中的名称值对mdl_csfor theSIM命令:

mdl ='vdp';load_system(MDL)CS = GetActiveConfigset(MDL);mdl_cs = cs.copy;set_param(mdl_cs,'abstol',,,,'1e-5',,,,...“ savestate',,,,'上',,,,'StateSaveName',,,,'xoutnew',,,,...'SaveOutput',,,,'上',,,,'OutputSaveName',,,,'Youtnew')simout = sim(mdl,mdl_cs)
模拟= Simulink.SimulationOutput: xoutNew: [65x2 double] youtNew: [65x2 double] SimulationMetadata: [1x1 Simulink.SimulationMetadata] ErrorMessage: [0x0 char]

输入参数

全部收缩

模拟模型,指定为字符向量。

Example:simout = sim('vdp')

包含参数设置的结构for the simulation specified as a structure. The fields in the structure are the names of the configuration parameters, and the corresponding values are the parameter values.

模型的配置参数集,指定为Simulink.Configset目的。有关更多信息,请参阅Simulink.ConfigSet

模型的仿真输入对象,指定为万博1manbetxSimulink.SimulationInput通过指定模型名称创建的对象。有关更多信息,请参阅万博1manbetxSimulink.SimulationInput

使用SimulationInput对象指定块参数,模型参数,变量和外部输入以进行仿真。

Example:SIM我n= Simulink.SimulationInput('vdp')

名称值参数

将可选的参数对name1 = value1,...,namen = valuen,,,,where姓名是参数名称和价值is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

在R2021a之前,请使用逗号分隔每个名称和值,并附上姓名in quotes.

Example:'求解器','ode15s','timeout','30'specifies that the model is simulated using the ode15s solver with a timeout that occurs whenSiimulation时间reaches 30.

您可以将任何模型参数及其值传递给SIM命令。

除此之外SIM命令接受以下参数Configsetset_param

Option to save errors to SimulationMetadata object, specified as 'off' or 'on'. By default, if an error occurs during simulation, theSIM命令停止并报告MATLAB中的错误®命令窗口。如果指定“捕获”,“在”上, 这SIM命令将任何错误保存到错误诊断内部的结构仿真metadata目的。这error message is saved in the错误信息property of the仿真图目的。

When running multiple simulations in a loop, this option ensures that one simulation error will not stop a script or function from continuing.

如果指定输入对象的数组,则SIM命令运行CaptureErrors已启用。如果发生错误,则错误消息包含在万博1manbetxSimulink.SimulationMetadata目的for the simulation, as well as simulation data up to the point of the failure.

this option is not available for simulation in SIL and PIL modes.

Example:“捕获”,“在”上

仿真的调试模式选项,指定为“ OFF”或“ ON”。设置值'调试'argument to'上'starts the simulation in debug mode (see调试器图形用户界面了解更多信息)。此选项的值可以是启动后要发送到调试器的单元格数组。

Example:'调试',,'上'

此选项仅在快速加速器模式下可用。预先模拟的最新检查,指定为“ ON”或“ OFF”。如果将此值设置为'离开',模万博1manbetx型不执行一个最新的检查。我t skips the start/stop callbacks in blocks. If you call theSIM命令来自parfor,将此值设置为'离开'

When you set this option to'离开',,,,changes that you make to block parameter values in the model (for example, by using block dialog boxes, by using theset_param函数,或通过更改MATLAB变量的值)不影响仿真。利用RapidAcceleratorParameterset将新的参数值直接传递给模拟。

Example:“ RapidAcceleratoruptoptatecheck”,“关闭”

最大模拟运行时间,指定为正标量。在几秒钟内指定时间以允许模拟运行。如果您运行模型的时间长于暂停, 这software issues a warning and stops the simulation.暂停指模拟花费的时间。

Example:'timeOut',60

模拟跟踪设施,指定为:

  • 'Minstep'指定当解决方案突然变化时,模拟会停止,以至于可变步骤求解器无法采取步骤并满足误差公差。

  • 'siminfo'provides a short summary of the simulation parameters in effect at the start of simulation.

Example:'trace','minstep','Trace','siminfo'

快速重新启动选项的仿真选项,指定为“ ON”。快速重新启动允许您执行迭代模拟,而无需编译模型或每次终止模拟。

环境'oponerror''上'stops the execution of simulations if an error is encountered.

指定用于评估模型中定义的MATLAB表达式的工作空间。环境srcworkspace对在加速器模式下执行的引用模型没有影响。环境srcworkspace到达parfor循环会违反透明度。

Example:'srcworkspace',“当前”

Output Arguments

全部收缩

Simulation object containing logged simulation results, returned as a万博1manbetxsimulink.simulationOutput包含所有记录的模拟结果的对象。

所有仿真输出(已记录时间,状态和信号)都返回单个万博1manbetxsimulink.simulationOutput目的。you select the data to be logged, such as the model time, states, and output that is logged using the数据导入/导出pane of theModel Configuration Parameters对话框。您可以使用块(例如到工作区Scopeblocks. For more information on signal logging, see信号记录

更多关于

全部收缩

向后兼容语法

从R2009b开始,SIM增强了命令,以提供与并行计算更大的兼容性。改进single-output format将所有仿真结果保存到一个对象,简化输出变量的管理。

有关与R2009A或更早版本的兼容性,请使用此语法:

[[t,,,,X,,,,y] =SIM('模型',,timespan,,,,Options,,,,UT)[t,,,,X,,,,y1,,,,。。。,,,,yn] =SIM('模型',,timespan,,,,Options,,,,UT

如果指定上ly the模型参数,Simulin万博1manbetxk自动将时间,状态和输出保存到指定的输出参数。

如果you do not specify any output arguments, Simulink determines what data to log based on the settings for the配置参数>数据导入/导出窗格。万博1manbetxSimulink将模拟输出存储在当前工作区或变量中Ans,基于将仿真输出保存为一个对象parameter.

向后兼容语法输入和输出参数
Argument Description
t

时间向量返回。

X

这state returned in matrix or structure format. The state matrix contains continuous states followed by discrete states.

y

这output returned in matrix or structure format. For block diagram models, this variable contains all root-level blocks.

y1,,,,。。。,,,,yn

这outports, which can only be specified for diagram models. Here,n必须是根级块的数量。每个郊区都将在y1,...,,,yn变量。

'模型'

这name of the model to simulate.

timespan

时间板可以是tFinal,,,,[tfinal], 或者[TSTART OUTUPTTIMY TFINAL]。输出时间是返回的时间点t,,,,but in general,t包括其他时间点。

Options

在结构中创建的可选仿真参数模拟使用名称值对的命令。

UT

Optional external inputs. For supported expressions, see将数据加载到根级输入端口

Simulink requires only the模型争论。万博1manbetxSimulink从框图中获取所有默认值,包括未指定的选项。如果指定任何可选参数,则指定的设置覆盖了框图中的设置。

指定输入参数SIMas the empty matrix,[],使Simulin万博1manbetxk使用该参数使用默认值。

tips

  • 使用SIM命令覆盖在Model Configuration Parameters对话框。该软件在仿真末尾还原原始配置值。

  • 在里面case of a model with aModel块,应用于参数规范the top model.

  • 在使用无限停止时间模拟模型时,要停止模拟,您必须按下ctrl+cctrl+c打破仿真,模拟结果未保存在MATLAB工作区中。

  • 要指定模拟的时间跨度,您必须指定StartTime停止时间参数。

  • 要记录模型时间,状态或输出,请使用数据导入/导出pane of the Model Configuration Parameters dialog box.

  • 要记录信号,要么使用到工作区block such as the到工作区block or theScope块,或使用信号记录。有关更多信息,请参阅使用信号记录导出信号数据

  • 获取模型的仿真参数列表vdp,,,,in the MATLAB Command Window, enter:

    configset = getActiveconfigset('vdp')configsetnames = get_param(configset,'objectparameters')

    this command lists several object parameters, including simulation parameters such as“停止时间”,,,,'SaveTime',,,,“ savestate',,,,'SaveOutput', 和“信号”

版本历史记录

在R2006a之前引入