Main Content

instantiate

Create analysis instance from specification

Description

instance = instantiate(arch,properties,name) creates an instance instance named name of a model architecture arch with properties properties for analysis. Get the Architecture property of the systemcomposer.arch.Model object model using model.Architecture in the MATLAB® Command Window.

Note

This function is part of the instance programmatic interfaces that you can use to analyze the model iteratively, element-by-element. The instance refers to the element instance on which the iteration is being performed.

example

instance = instantiate(arch,profile,name) creates an instance instance named name of a model architecture arch with all stereotypes in a profile profile for analysis.

example

instance = instantiate(___,Name=Value) creates an instance of a model architecture for analysis with additional arguments.

example

Examples

collapse all

Instantiate all properties of stereotypes in a profile that will be applied to specific elements during instantiation.

Create a profile for latency characteristics and save it.

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

Create a new model and apply the profile to the model.

model = systemcomposer.createModel("archModel");
model.applyProfile("LatencyProfile");

Specify type of elements each stereotype can be applied on.

NodeLatency = struct("elementKinds",["Component"]);
ConnectorLatency = struct("elementKinds",["Connector"]);
LatencyBase = struct("elementKinds",["Connector","Port","Component"]);
PortLatency = struct("elementKinds",["Port"]);

Create the analysis structure.

LatencyAnalysis = struct("NodeLatency",NodeLatency, ...
                "ConnectorLatency",ConnectorLatency, ...
                "PortLatency",PortLatency, ...
                "LatencyBase",LatencyBase);

Create the properties structure.

properties = struct("LatencyProfile",LatencyAnalysis);

Instantiate all properties of stereotypes in the profile.

instance = instantiate(model.Architecture,properties,"NewInstance")

Instantiate specific properties of stereotypes in a profile that will be applied to specific elements during instantiation.

Create a profile for latency characteristics and save it.

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

Create a new model and apply the profile to the model.

model = systemcomposer.createModel("archModel");
model.applyProfile("LatencyProfile");

Specify some properties of the stereotypes in the profile.

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);

Create the properties structure.

properties = struct("LatencyProfile",LatencyAnalysis);

Instantiate some properties of stereotypes in the profile.

instance = instantiate(model.Architecture,properties,"NewInstance")

Instantiate all stereotypes already in a profile that will be applied to elements during instantiation.

Create a profile for latency characteristics and save it.

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

Create a new model and apply the profile to the model.

model = systemcomposer.createModel("archModel");
model.applyProfile("LatencyProfile");

Instantiate all stereotypes in a profile.

instance = instantiate(model.Architecture,"LatencyProfile","NewInstance")

Create an instantiation for analysis for a system with latency in its wiring. The materials used are copper, fiber, and Wi-Fi®.

Create Latency Profile with Stereotypes and Properties

Create a System Composer™ profile with a base, connector, component, and port stereotype. Add properties with default values to each stereotype as needed for analysis.

profile = systemcomposer.profile.Profile.createProfile("LatencyProfileC");

Add a base stereotype with properties.

latencybase = profile.addStereotype("LatencyBase");
latencybase.addProperty("latency",Type="double");
latencybase.addProperty("dataRate",Type="double",DefaultValue="10");

Add a connector stereotype with properties.

connLatency = profile.addStereotype("ConnectorLatency",...
    Parent="LatencyProfileC.LatencyBase");
connLatency.addProperty("secure",Type="boolean",DefaultValue="true");
connLatency.addProperty("linkDistance",Type="double");

Add a component stereotype with properties.

nodeLatency = profile.addStereotype("NodeLatency",...
    Parent="LatencyProfileC.LatencyBase");
nodeLatency.addProperty("resources",Type="double",DefaultValue="1");

Add a port stereotype with properties.

portLatency = profile.addStereotype("PortLatency",...
    Parent="LatencyProfileC.LatencyBase");
portLatency.addProperty("queueDepth",Type="double",DefaultValue="4.29");
portLatency.addProperty("dummy",Type="int32");

Instantiate Using Analysis Function

Create a new model and apply the profile. Create components, ports, and connections in the model. Apply stereotypes to the model elements. Finally, instantiate using the analysis function.

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;

Apply profile to model.

model.applyProfile("LatencyProfileC");

Create components, ports, and connections.

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);

Clean up the canvas.

Simulink.BlockDiagram.arrangeSystem("archModel"); 

Batch apply stereotypes to model elements.

batchApplyStereotype(arch,"Component","LatencyProfileC.NodeLatency");
batchApplyStereotype(arch,"Port","LatencyProfileC.PortLatency");
batchApplyStereotype(arch,"Connector","LatencyProfileC.ConnectorLatency");

Instantiate using the analysis function.

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'

Inspect Component, Port, and Connector Instances

Get properties from component, port, and connector instances.

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

Input Arguments

collapse all

Architecture, specified as a systemcomposer.arch.Architecture object.

Stereotype properties, specified as a structure containing profile, stereotype, and property information. Use properties to specify which stereotypes and properties need to be instantiated. For more details, see Instantiate All Properties of Stereotypes in Profile and Instantiate Specific Properties of Stereotypes in Profile.

Data Types: struct

Name of instance generated from the model, specified as a character vector or string.

Example: "NewInstance"

Data Types: char | string

Profile name, specified as a character vector or string.

Example: 'LatencyProfile'

Data Types: char | string

Name-Value Arguments

collapse all

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Example: instantiate(model.Architecture,"LatencyProfile","NewInstance",Function=@calculateLatency,Arguments="3",Strict=true,NormalizeUnits=false,Direction="PreOrder")

Whether to normalize value based on units, if any, specified in property definition upon instantiation, specified as 1 (true) or 0 (false).

Example: instantiate(model.Architecture,'LatencyProfile','NewInstance','NormalizeUnits',true)

Data Types: logical

Analysis function, specified as the MATLAB function handle to be executed when analysis is run.

Analysis arguments, specified as a character vector, string, array of strings, or a cell array of character vectors of optional arguments to the analysis function.

Data Types: char | string

Iteration type, specified as "PreOrder", "PostOrder", "TopDown", or "BottomUp".

  • Pre-order — Start from the top level, move to a child component, and process the subcomponents of that component recursively before moving to a sibling component.

  • Top-Down — Like pre-order, but process all sibling components before moving to their subcomponents.

  • Post-order — Start from components with no subcomponents, process each sibling, and then move to parent.

  • Bottom-up — Like post-order, but process all subcomponents at the same depth before moving to their parents.

Data Types: char | string

Condition for instances getting properties only if the specification of the instance has the stereotype applied, specified as 1 (true) or 0 (false).

Data Types: logical

Output Arguments

collapse all

Architecture instance, returned as a systemcomposer.analysis.ArchitectureInstance object.

More About

collapse all

Version History

Introduced in R2019a