将子系统转换为参考模型
Model reference offers benefits for modeling large, complex systems and for team-based development. Many large models use a combination of subsystems and referenced models. To decide whether to convert a subsystem to a referenced model, see在模型组件的类型中选择。
准备子系统进行转换
准备转换子系统可以消除或减少转化过程中确定的问题数量。在转化之前解决这些问题可能比在诊断消息之间反复切换更有效金宝app®编辑。
To prepare the subsystem:
设置Signal resolutionconfiguration parameter to
Explicit only
orNone
。提示
You can automatically fix this issue during conversion.
配置Subsystemblock interface.
提示
您可以在转换过程中自动解决这些接口问题。
子系统接口 要找什么 模型修改 GotoorFrom块
GotoorFrom越过子系统边界的块
代替From块that have a correspondingGotoblock that crosses the subsystem boundary with anInport堵塞。
代替eachGoto具有相应的块From与子系统边界交叉边界的块Outport堵塞。
连接InportandOutport块to the corresponding subsystem ports.
Data stores
Data Store Memory块accessed by数据存储读取orData Store Write块from outside of the subsystem
更换Data Store Memory使用全球数据存储块。使用一个
Simulink.Signal
目的。有关详细信息,请参阅带信号对象的数据存储。Tunable parameters
Global tunable parameters in the dialog box opened using the配置参数>代码生成>Optimization>Configure按钮
To create a
Simulink.Parameter
object for each tunable parameter, usetunablevars2parameterobjects
。这
Simulink.Parameter
对象必须有一个存储等级Auto
。For more information, see可重复使用的参考模型的参数化实例andTunable Parameters。
配置Subsystem块内容。
Subsystem Configuration 要找什么 模型修改 Block execution order Virtual subsystem that does not force contained blocks to execute consecutively.
选择theSubsystem街区,然后在子系统块tab, selectIs Atomic Subsystem。 Function calls
跨虚拟子系统边界的功能通信信号
移动函数通话发生器阻止要转换的子系统。
笔记
如果您转换出导出功能子系统,则无需移动函数通话发生器堵塞。
功能通话输出
Change the function-call outputs to data triggers.
宽功能通话端口
Eliminate wide signals for function-call subsystems.
样本时间
一个Inportblock sample time that does not match the sample time of the block driving theInportblock
插入率转换在适当的地方进行块。
Inport blocks
合并Inport块
配置模型以避免合并Inport块。See the合并block documentation.
恒定块
Constant为子系统提供输入的块
MoveConstant进入子系统。
公共汽车
进入和退出子系统的公共汽车
匹配信号名称和总线元素名称子系统内部的块。
要查找不匹配总线元素名称的信号名称,请使用信号标签不匹配诊断。
公共汽车中的重复信号名称
使公交元素的信号名称与众不同。
Signal names that are not valid MATLAB®identifiers. A valid identifier is a character vector that meets these conditions:
该名称包含字母,数字或下划线。
第一个角色是一封信。
名称的长度小于或等于
Namelengthmax
功能。
Change any invalid signal names to be valid MATLAB identifiers.
Make sure that the model containing the subsystem that you want to convert compiles successfully.
将子系统转换为参考模型
要将子系统转换为参考模型,请打开型号参考转换顾问by selecting aSubsystem街区,在子系统块tab, selecting转变>模型块。这型号参考转换顾问lets you interactively specify conversion parameters and fix issues that the advisor finds.
To make the conversion process faster:
在模型参考转换顾问中,选择自动修复错误(如果可能的话)。此选项会自动解决一些转换问题,但您不控制修复程序。
关闭any open范围block windows before starting the conversion.
To leave theSubsystem将其封锁并从内容的内容创建一个单独的模型Subsystemblock, clear用模型块替换子系统的内容。
要比较转换之前和之后的顶级模拟结果:
Enable signal logging for output signals of interest.
选择Check simulation results after conversionand用模型块替换子系统的内容。
设置Stop time,,,,Absolute tolerance,,,,andRelative tolerance。
设置模型块仿真模式在顾问中的选项与原始模型相同的仿真模式。
After you set the conversion settings, click转变并解决任何已确定的问题。
Alternatively, in the MATLAB command window, use theSimulink.SubSystem.convertToModelReference
功能。您可以转换多个Subsystem使用一个块Simulink.SubSystem.convertToModelReference
命令。但是,您不能同时转换父系子系统和该子系统的孩子。
Conversion Results
在所有转换检查通过后,Simulink:金宝app
Creates a referenced model from the subsystem.
Creates the
Simulink.Bus
对象,Simulink.Signal
引用模型需要的对象和可调参数。By default, replaces theSubsystemblock with aModelblock that references the new model.
插入Model块Subsystem阻止自动修复程序添加到Modelblock interface.
Creates an HTML conversion summary report in the
slprj
folder. This report summarizes the results of the conversion process, including the results of the fixes that the advisor performed. This report also describes the elements that it copies.Optionally checks the consistency of simulation results before and after conversion.
Simulink copies the following elements from the original model to the new referenced model.
配置集— If the parent model uses:
不是引用配置集的配置集,顾问将整个配置设置复制为引用模型
一个引用configuration set, then both the parent and referenced models use the same referenced configuration set
Variables— The advisor copies only the model workspace variables that the subsystem used in the original model to the model workspace of the referenced model. If the model that contained the subsystem uses a data dictionary, then the referenced model uses the same data dictionary.
Requirements links— The advisor copies requirements links created withRequirements Toolbox™software to theModelblock from the originalSubsystem堵塞。
Compare Simulation Results Before and After Conversion
After you successfully complete conversion, use the单击此处查看比较结果关联。结果显示在仿真数据检查器。绿色检查标记表明,使用新参考模型的基线模型和模型之间的模拟结果在公差之内。
For more information, see比较仿真数据。
恢复转换
If you are not satisfied with the conversion results, you can restore the model to its initial state. Use one of these approaches:
At any point during the conversion, selectFile>负载还原点。
After you successfully run the完整的转换check, use theClick here to restore the original model关联。
Integrate Referenced Model into Parent Model
After you complete the conversion, update the model as necessary to meet your modeling requirements. For example, you can manually replace aSubsystemblock with aModelblock that references the created referenced model.
如果你想模拟模型与外部哒ta, check that the rootInport新参考模型中的块具有适当的插值数据parameter setting. See the documentation for the插值数据parameter of theInport堵塞。