Main Content


Define connections for member component ports in composite component

Parent Section: component


    connect(a, b);


connections begins the structure section in a composite component file; this section is terminated by an end keyword. It is executed once during compilation. The structure section contains information on how the constituent components’ ports are connected to one another and to the external inputs, outputs, and nodes of the top-level component. All member components declared in the components declaration block are available by their names in the structure section.

The connections block contains a set of connect constructs, which describe both the conserving connections (between nodes) and the physical signal connections (between the inputs and outputs). To refer to a node, input, or output of a member component, use the syntax comp_name.port_name, where comp_name is the identifier assigned to the member component in the components declaration block and port_name is the name of the node, input, or output in the member component file.

The following syntax connects node a of the composite component to node a of the member component c1, node b of the member component c1 to node a of the member component c2, and node b of the member component c2 to node b of the composite component.

      connect(a, c1.a);
      connect(c1.b, c2.a);
      connect(c2.b, b);

See the connect reference page for more information on the connect construct syntax.

You can also use for loops to declare an array of member components and specify the component connections. For more information, see Component Arrays.


expand all

This example implements a simple RC circuit that models the discharging of an initially charged capacitor. The composite component uses the components from the Simscape™ Foundation library as building blocks, and connects them as shown in the following block diagram.

component CircuitRC
     Out = { 0.0, 'V' }; % I:right
      p1 = {1e-6, 'F'};  % Capacitance
      p2 = {10, 'Ohm'};  % Resistance
      c1 = foundation.electrical.elements.capacitor(c=p1);
      VoltSensor = foundation.electrical.sensors.voltage;
      r1 = foundation.electrical.elements.resistor(R=p2);
      Grnd = foundation.electrical.elements.reference;
      connect(Grnd.V, c1.n, r1.n, VoltSensor.n);
      connect(VoltSensor.p, r1.p, c1.p);
      connect(VoltSensor.V, Out);

The connections block contains three connect constructs:

  • The first one connects the negative ports of the capacitor, resistor, and voltage sensor to each other and to ground

  • The second one connects the positive ports of the capacitor, resistor, and voltage sensor to each other

  • The third one connects the physical signal output port of the voltage sensor to the external output Out of the composite component

The resulting composite block has one physical signal output port, Out, and three externally adjustable parameters in the block dialog box: Capacitance, Initial voltage, and Resistance.

Version History

Introduced in R2012b