instantiate
根据规范创建分析实例
语法
说明
创建一个名为 instance
= instantiate(arch
,properties
,name
)name
的模型架构 arch
的 instance
实例,并带有 properties
属性,以供分析。在 MATLAB® 命令行窗口中使用 model.Architecture
获取 systemcomposer.arch.Model
对象 model
的 Architecture
属性。
注意
该函数是实例编程接口的一部分,可用于逐元素迭代分析模型。instance
指的是执行迭代的元素实例。
创建一个带有附加参量的分析模型架构实例。instance
= instantiate(___,Name=Value
)
示例
实例化配置文件中将应用于特定元素的构造型的所有属性。
创建延迟特性配置文件并保存。
profile = systemcomposer.profile.Profile.createProfile("LatencyProfile"); latencybase = profile.addStereotype("LatencyBase"); latencybase.addProperty("latency",Type="double"); latencybase.addProperty("dataRate",Type="double",DefaultValue="10"); connLatency = profile.addStereotype("ConnectorLatency",... Parent="LatencyProfile.LatencyBase"); connLatency.addProperty("secure",Type="boolean"); connLatency.addProperty("linkDistance",Type="double"); nodeLatency = profile.addStereotype("NodeLatency",... Parent="LatencyProfile.LatencyBase"); nodeLatency.addProperty("resources",Type="double",DefaultValue="1"); portLatency = profile.addStereotype("PortLatency",... Parent="LatencyProfile.LatencyBase"); portLatency.addProperty("queueDepth",Type="double"); portLatency.addProperty("dummy",Type="int32"); profile.save
创建一个新模型,并将配置文件应用于该模型。
model = systemcomposer.createModel("archModel"); model.applyProfile("LatencyProfile");
指定每个构造型可应用的元素类型。
NodeLatency = struct("elementKinds",["Component"]); ConnectorLatency = struct("elementKinds",["Connector"]); LatencyBase = struct("elementKinds",["Connector","Port","Component"]); PortLatency = struct("elementKinds",["Port"]);
创建分析结构。
LatencyAnalysis = struct("NodeLatency",NodeLatency, ... "ConnectorLatency",ConnectorLatency, ... "PortLatency",PortLatency, ... "LatencyBase",LatencyBase);
创建属性结构。
properties = struct("LatencyProfile",LatencyAnalysis);
实例化配置文件中构造型的所有属性。
instance = instantiate(model.Architecture,properties,"NewInstance")
在配置文件中实例化构造型的特定属性,这些属性将在实例化过程中应用于特定元素。
创建延迟特性配置文件并保存。
profile = systemcomposer.profile.Profile.createProfile("LatencyProfile"); latencybase = profile.addStereotype("LatencyBase"); latencybase.addProperty("latency",Type="double"); latencybase.addProperty("dataRate",Type="double",DefaultValue="10"); connLatency = profile.addStereotype("ConnectorLatency",... Parent="LatencyProfile.LatencyBase"); connLatency.addProperty("secure",Type="boolean"); connLatency.addProperty("linkDistance",Type="double"); nodeLatency = profile.addStereotype("NodeLatency",... Parent="LatencyProfile.LatencyBase"); nodeLatency.addProperty("resources",Type="double",DefaultValue="1"); portLatency = profile.addStereotype("PortLatency",... Parent="LatencyProfile.LatencyBase"); portLatency.addProperty("queueDepth",Type="double"); portLatency.addProperty("dummy",Type="int32"); profile.save
创建一个新模型,并将配置文件应用于该模型。
model = systemcomposer.createModel("archModel"); model.applyProfile("LatencyProfile");
指定配置文件中构造型的某些属性。
NodeLatency = struct("elementKinds",["Component"], ... "properties",struct("resources",true)); ConnectorLatency = struct("elementKinds",["Connector"], ... "properties",struct("secure",true,"linkDistance",true)); LatencyBase = struct("elementKinds",[], ... "properties",struct("dataRate",true,"latency",false)); PortLatency = struct('elementKinds',["Port"], ... "properties",struct("queueDepth",true)); LatencyAnalysis = struct("NodeLatency",NodeLatency, ... "ConnectorLatency",ConnectorLatency, ... "PortLatency",PortLatency, ... "LatencyBase",LatencyBase);
创建属性结构。
properties = struct("LatencyProfile",LatencyAnalysis);
在配置文件中实例化构造型的某些属性。
instance = instantiate(model.Architecture,properties,"NewInstance")
实例化配置文件中的所有构造型,这些构造型将在实例化过程中应用于元素。
创建延迟特性配置文件并保存。
profile = systemcomposer.profile.Profile.createProfile("LatencyProfile"); latencybase = profile.addStereotype("LatencyBase"); latencybase.addProperty("latency",Type="double"); latencybase.addProperty("dataRate",Type="double",DefaultValue="10"); connLatency = profile.addStereotype("ConnectorLatency",... Parent="LatencyProfile.LatencyBase"); connLatency.addProperty("secure",Type="boolean"); connLatency.addProperty("linkDistance",Type="double"); nodeLatency = profile.addStereotype("NodeLatency",... Parent="LatencyProfile.LatencyBase"); nodeLatency.addProperty("resources",Type="double",DefaultValue="1"); portLatency = profile.addStereotype("PortLatency",... Parent="LatencyProfile.LatencyBase"); portLatency.addProperty("queueDepth",Type="double"); portLatency.addProperty("dummy",Type="int32"); profile.save
创建一个新模型,并将配置文件应用于该模型。
model = systemcomposer.createModel("archModel"); model.applyProfile("LatencyProfile");
实例化配置文件中的所有构造型。
instance = instantiate(model.Architecture,"LatencyProfile","NewInstance")
为布线有延迟的系统创建分析实例。使用的材料有铜、光纤和 Wi-Fi®。
使用构造型和属性创建延迟配置文件
创建一个 System Composer™ 配置文件,其中包含基础、连接器、组件和端口构造型。根据分析需要,为每个构造型添加带有默认值的属性。
profile = systemcomposer.profile.Profile.createProfile("LatencyProfileC");
添加带有属性的基本构造型。
latencybase = profile.addStereotype("LatencyBase"); latencybase.addProperty("latency",Type="double"); latencybase.addProperty("dataRate",Type="double",DefaultValue="10");
添加一个带有属性的连接器构造型。
connLatency = profile.addStereotype("ConnectorLatency",... Parent="LatencyProfileC.LatencyBase"); connLatency.addProperty("secure",Type="boolean",DefaultValue="true"); connLatency.addProperty("linkDistance",Type="double");
添加带有属性的组件构造型。
nodeLatency = profile.addStereotype("NodeLatency",... Parent="LatencyProfileC.LatencyBase"); nodeLatency.addProperty("resources",Type="double",DefaultValue="1");
添加带有属性的端口构造型。
portLatency = profile.addStereotype("PortLatency",... Parent="LatencyProfileC.LatencyBase"); portLatency.addProperty("queueDepth",Type="double",DefaultValue="4.29"); portLatency.addProperty("dummy",Type="int32");
使用分析函数实例化
创建新模型并应用配置文件。在模型中创建组件、端口和连接。对模型元素应用构造型。最后,使用分析函数进行实例化。
model = systemcomposer.createModel("archModel"); systemcomposer.openModel("archModel")
ans = Model with properties: Name: 'archModel' SimulinkHandle: 153.0012 Architecture: [1×1 systemcomposer.arch.Architecture] Profiles: [0×0 systemcomposer.profile.Profile] InterfaceDictionary: [1×1 systemcomposer.interface.Dictionary] Views: [0×0 systemcomposer.view.View] Interactions: [0×0 systemcomposer.interaction.Interaction]
arch = model.Architecture;
将配置文件应用到模型。
model.applyProfile("LatencyProfileC");
创建组件、端口和连接。
componentSensor = addComponent(arch,"Sensor"); sensorPorts = addPort(componentSensor.Architecture,{'MotionData','SensorPower'},{'in','out'}); componentPlanning = addComponent(arch,"Planning"); planningPorts = addPort(componentPlanning.Architecture,... {'Command','SensorPower','MotionCommand'},... {'in','in','out'}); componentMotion = addComponent(arch,"Motion"); motionPorts = addPort(componentMotion.Architecture,... {'MotionCommand','MotionData'},{'in','out'}); c_sensorData = connect(arch,componentSensor,componentPlanning); c_motionData = connect(arch,componentMotion,componentSensor); c_motionCommand = connect(arch,componentPlanning,componentMotion);
清理画布。
Simulink.BlockDiagram.arrangeSystem("archModel");
对模型元素批量应用构造型。
batchApplyStereotype(arch,"Component","LatencyProfileC.NodeLatency"); batchApplyStereotype(arch,"Port","LatencyProfileC.PortLatency"); batchApplyStereotype(arch,"Connector","LatencyProfileC.ConnectorLatency");
使用分析函数进行实例化。
instance = instantiate(model.Architecture,"LatencyProfileC","NewInstance",... Function=@calculateLatency,Arguments="3", ... Strict=true,NormalizeUnits=false,Direction="PreOrder")
instance = ArchitectureInstance with properties: Specification: [1×1 systemcomposer.arch.Architecture] IsStrict: 1 NormalizeUnits: 0 AnalysisFunction: @calculateLatency AnalysisDirection: PreOrder AnalysisArguments: '3' ImmediateUpdate: 0 listenerFnc: [] Components: [1×3 systemcomposer.analysis.ComponentInstance] Ports: [0×0 systemcomposer.analysis.PortInstance] Connectors: [1×3 systemcomposer.analysis.ConnectorInstance] Parameters: [0×0 systemcomposer.analysis.InstanceParameter] Name: 'NewInstance'
检查组件、端口和连接器实例
从组件、端口和连接器实例中获取属性。
defaultResources = instance.Components(1).getValue("LatencyProfileC.NodeLatency.resources")
defaultResources = 1
defaultSecure = instance.Connectors(1).getValue("LatencyProfileC.ConnectorLatency.secure")
defaultSecure = logical
1
defaultQueueDepth = instance.Components(1).Ports(1).getValue("LatencyProfileC.PortLatency.queueDepth")
defaultQueueDepth = 4.2900
输入参数
架构,指定为 systemcomposer.arch.Architecture
对象。
构造型属性,指定为包含配置文件、构造型和属性信息的结构。使用 properties
指定需要实例化的构造型和属性。更多详细信息,请参阅在配置文件中实例化构造型的所有属性和在配置文件中实例化构造型的特定属性。
数据类型: struct
从模型生成的实例名称,指定为字符向量或字符串。
示例: "NewInstance"
数据类型: char
| string
配置文件名称,指定为字符向量或字符串。
示例: 'LatencyProfile'
数据类型: char
| string
名称-值参数
以 Name1=Value1,...,NameN=ValueN
的形式指定可选参量对组,其中 Name
是参量名称,Value
是对应的值。名称-值参量必须出现在其他参量之后,但对各个参量对组的顺序没有要求。
在 R2021a 之前,使用逗号分隔每个名称和值,并用引号将 Name
引起来。
示例: instantiate(model.Architecture,"LatencyProfile","NewInstance",Function=@calculateLatency,Arguments="3",Strict=true,NormalizeUnits=false,Direction="PreOrder")
是否在实例化时根据属性定义中指定的单位(如果有)对数值进行归一化,指定为 1
(true
) 或 0
(false
)。
示例: instantiate(model.Architecture,'LatencyProfile','NewInstance','NormalizeUnits',true)
数据类型: logical
分析函数,指定为运行分析时要执行的 MATLAB 函数句柄。
分析参量,指定为字符向量、字符串、字符串数组或分析函数可选参量的字符向量元胞数组。
数据类型: char
| string
迭代类型,指定为 "PreOrder"
、"PostOrder"
、"TopDown"
或 "BottomUp"
。
Pre-order
- 从顶层开始,移至子组件,并递归处理该组件的子组件,然后再移至同级组件。Top-Down
- 与前序遍历类似,但在移至子组件之前先处理所有同级组件。Post-order
- 从没有子组件的组件开始,处理每个同级组件,然后移至父组件。Bottom-up
- 与后序遍历类似,但先处理所有同一深度的子组件,再将其移至父节点。
数据类型: char
| string
限定实例仅在实例设定应用了相应构造型时才能获取属性,指定为 1
(true
) 或 0
(false
)。
数据类型: logical
输出参量
架构实例,以 systemcomposer.analysis.ArchitectureInstance
对象的形式返回。
详细信息
术语 | 定义 | 应用 | 更多信息 |
---|---|---|---|
架构 | System Composer™ 架构代表由组件组成的系统,以及这些组件在结构上和行为上如何相互关联。 | 不同类型的架构描述系统的不同方面。您可以使用视图来可视化架构中的组件子集。您可以使用参数编辑器在架构层级上定义参数。 | |
根 | 根位于架构层次结构的顶层。根架构的边界由围绕相关系统的架构端口定义。 | 根架构的系统边界包围着您的架构模型。您可以添加架构端口来定义跨边界接口。 | |
模型 | System Composer 模型是包含架构信息的文件,涵盖组件、端口、连接器、接口和行为等信息。 | 对模型执行操作,包括提取根级架构、应用配置文件、链接接口数据字典或从模型架构生成实例。System Composer 模型存储为 SLX 文件。 | 创建带接口和需求链接的架构模型 |
组件 | 组件是系统中可替换的部分,用于在架构环境中实现明确的函数。组件定义架构元素,例如函数、另一个系统、硬件、软件或其他概念实体。组件也可以是子系统或子函数。 | 组件以模块的形式表示,是架构模型的一部分,并且可以分离成可重用的工件。使用接口编辑器通过端口接口在组件之间传输信息,使用参数编辑器传输参数。 | |
端口 | 端口是组件或架构上的节点,表示与其环境的交互点。通过端口,信息可以流向其他组件或系统,或者从其他组件或系统流入。 | 组件端口是组件上与其他组件之间的交互点。架构端口是系统边界上的端口,无论该边界是在组件内还是在整体架构模型内。根架构具有由其端口定义的边界。 | |
连接器 | 连接器是提供端口之间连接的线路。连接器描述信息如何在组件或架构之间流动。 | 通过连接器,两个组件可以进行交互,而无需定义交互的性质。在端口上设置接口来定义组件之间的交互方式。 |
术语 | 定义 | 应用 | 更多信息 |
---|---|---|---|
构造型 | 构造型提供了一种扩展核心语言元素和添加域特定元数据的机制。 | 将构造型应用于核心元素类型。一个元素可以有多个构造型。您可以利用构造型为不同的元素设置样式。构造型为元素提供了一组通用的属性,例如质量、成本和功率。 | |
属性 | 属性是构造型中的一个字段。您可以为应用了该构造型的每个元素指定属性值。 | 使用属性来存储与模型元素相关联的定量特征,例如重量或速度。属性也可以是描述性的,或者表示一种状态。您可以使用属性检查器查看和编辑架构模型中每个元素的属性。有关详细信息,请参阅在 System Composer 中使用属性检查器。 | |
配置文件 | 配置文件是一系列构造型的集合。 | 您可以使用配置文件来创建专门的元素类型域。使用配置文件编辑器编写配置文件并将配置文件应用于模型。您可以将用于工程的构造型存储在一个或多个配置文件中。当您保存配置文件时,它们会存储在 XML 文件中。 |
术语 | 定义 | 应用 | 更多信息 |
---|---|---|---|
分析 | 静态分析分析系统结构,针对某些特性对架构进行定量评估。静态分析使用分析函数以及系统模型中捕获的属性和参数的参数值。 | 使用分析计算系统的总体可靠性、质量卷积、性能或热特性,或执行大小、重量和功率 (SWaP) 分析以提高效率。 | |
分析函数 | 分析函数是一个 MATLAB 函数,它使用模型实例中每个元素的属性以及组件和架构层级的实例特定参数计算评估架构所需的值。 | 使用分析函数计算分析结果。 | |
实例模型 | 实例模型是实例的集合。 | 您可以根据模型的更改更新实例模型,但实例模型不会根据活动变体或模型引用的更改而更新。您可以使用保存在 | 运行分析函数 |
实例 | 实例是架构模型元素在给定时间点上的具体体现。 | 实例会冻结实例模型中组件的活动变体或模型引用。 | 创建用于分析的模型实例 |
版本历史记录
在 R2019a 中推出
另请参阅
工具
函数
iterate
|lookup
|save
|update
|refresh
|systemcomposer.analysis.loadInstance
|systemcomposer.analysis.deleteInstance
|getValue
|setValue
|hasValue
|getParameter
|getEvaluatedParameterValue
|getParameterNames
|getParameterValue
|setParameterValue
|isArchitecture
|isComponent
|isConnector
|isPort
|getQualifiedName
对象
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)