主要内容

本页采用了机器翻译。点击此处可查看最新英文版本。

instantiate

根据规范创建分析实例

说明

instance = instantiate(arch,properties,name) 创建一个名为 name 的模型架构 archinstance 实例,并带有 properties 属性,以供分析。在 MATLAB® 命令行窗口中使用 model.Architecture 获取 systemcomposer.arch.Model 对象 modelArchitecture 属性。

注意

该函数是实例编程接口的一部分,可用于逐元素迭代分析模型。instance 指的是执行迭代的元素实例。

示例

instance = instantiate(arch,profile,name) 创建一个名为 name 的模型架构 archinstance 实例,该实例包含配置文件 profile 中的所有构造型,以供分析。

示例

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 对象的形式返回。

详细信息

全部折叠

版本历史记录

在 R2019a 中推出