# connect

Block diagram interconnections of dynamic systems

## Syntax

## Description

connects the models and block diagram elements
`sysc`

= connect(`sys`

1,...`sys`

N,`inputs`

,`outputs`

)`sys`

`1,...`

`sys`

`N`

based on signal names. The `connect`

command interconnects the block
diagram elements by connecting input and output channels with matching names, as specified
in the `InputName`

and `OutputName`

properties of
`sys1,...,sysN`

. The aggregate model `sysc`

is a
dynamic system model with inputs and outputs specified by `inputs`

and
`outputs`

, respectively.

inserts an `sysc`

= connect(`sys`

1,...`sys`

N,`inputs`

,`outputs`

,`APs`

)`AnalysisPoint`

at every signal location
specified in `APs`

. Use analysis points to mark locations of interest
which are internal signals in the aggregate model. For instance, a location at which you
want to extract a loop transfer function or measure the stability margins is a location of
interest.

uses index-based interconnection to build `sysc`

= connect(`blksys`

,`connections`

,`inputs`

,`outputs`

)`sysc`

out of an aggregate,
unconnected model `blksys`

. The matrix `connections`

specifies how the outputs and inputs of `blksys`

interconnect. For
index-based interconnections, `inputs`

and `outputs`

are index vectors that specify which inputs and outputs of `blksys`

are
the external inputs and outputs of `sysc`

. This syntax can be convenient
when you do not want to assign names to all inputs and outputs of all models to connect.
However, in general, it is easier to keep track of named signals.

builds the interconnected model using additional options, including retaining unconnected
states that do not contribute to the dynamics of `sysc`

= connect(___,`opts`

)`sysc`

. To create
`opts`

, use `connectOptions`

. You can use
`opts`

with the input arguments of any of the previous syntaxes.

## Examples

**SISO Control System**

Create an aggregate model of the following block diagram from *r* to *y*.

This model contains a plant `G`

, a feedback controller `C`

, and a feedforward controller `F`

. Create dynamic system models representing each of these elements.

C = pid(2,1); G = zpk([],[-1,-1,-5],1); F = tf(3,[1 3]);

In preparation for building the block diagram using signal names, assign to each element the input and output names shown in the block diagram. To do so, set the `InputName`

and `OutputName`

properties of the elements.

C.InputName = "e"; C.OutputName = "uc"; G.InputName = "u"; G.OutputName = "y"; F.InputName = "r"; F.OutputName = "uf";

The block diagram also contains two summing junctions. One summing junction takes the difference between the reference signal *r* and the plant output *y* to compute the error signal *e*. The other summing junction adds the feedforward controller output *uf* to the feedback controller output `uc`

to compute the plant input *u*. Use the `sumblk`

command to create these summing junctions. To use `sumblk`

, write the expression for the summing junction as a string.

S1 = sumblk("e = r - y"); S2 = sumblk("u = uc + uf");

`sumblk`

returns a `tf`

model object representing the sum, with the input names and output names you provide in the expression. For instance, examine the signal names of `S1`

.

S1

S1 = From input "r" to output "e": 1 From input "y" to output "e": -1 Static gain.

You can now combine all the elements to create an aggregate model representing the response of the system in the block diagram from *r* to *y*. Provide `connect`

with the list of elements to combine, the desired input signal of the aggregate model `r`

, and the desired output signal `y`

. The `connect`

command automatically joins the elements by connecting inputs and outputs with matching names.

T = connect(G,C,F,S1,S2,"r","y"); size(T)

State-space model with 1 outputs, 1 inputs, and 5 states.

T.InputName

`ans = `*1x1 cell array*
{'r'}

T.OutputName

`ans = `*1x1 cell array*
{'y'}

### MIMO Control System

Create the control system of the previous example, where `G`

, `C`

, and `F`

are all two-input, two-output models.

In this example, the signals *r*, *y*, *e*, and so on are all vector signals of two elements each. First, create the models and name their inputs and outputs.

C = [pid(2,1), 0; 0,pid(5,6)]; F = [tf(3,[1 3]), 0; 0, tf(3,[1 3])]; G = ss(-1,[1,2],[1;-1],0);

Assign the input and output names.

C.InputName = "e"; C.OutputName = "uc"; G.InputName = "u"; G.OutputName = "y"; F.InputName = "r"; F.OutputName = "uf";

When you assign single names to vector-valued signals, the software automatically applies vector expansion to give each input and output channel a unique name. For instance, examine the names of the plant inputs.

G.InputName

`ans = `*2x1 cell*
{'u(1)'}
{'u(2)'}

This example uses vector expansion for the signal names of all MIMO components of the block diagram. You can instead name the signals individually, provided that you match the names of signals you want to join. For an example that uses individually named signals for some block-diagram elements, see MIMO Control System with Fixed and Tunable Components.

Next, create the vector-valued summing junction. `sumblk`

also automatically expands the signal names you provide in the sum expression for the vector signals, as you can verify by examining the input names of `S2`

.

S1 = sumblk("e = r - y",2); S2 = sumblk("u = uc + uf",2); S2.InputName

`ans = `*4x1 cell*
{'uc(1)'}
{'uc(2)'}
{'uf(1)'}
{'uf(2)'}

Combine all the elements to create an aggregate model representing the response *r* to *y*, that is, from [*r*(1),*r*(2)] to [*y*(1),*y*(2)].

T = connect(G,C,F,S1,S2,"r","y"); size(T)

State-space model with 2 outputs, 2 inputs, and 5 states.

T.InputName

`ans = `*2x1 cell*
{'r(1)'}
{'r(2)'}

T.OutputName

`ans = `*2x1 cell*
{'y(1)'}
{'y(2)'}

### Feedback Loop with Analysis Point

Consider the following block diagram.

You can create a model of this closed-loop system using `feedback`

and use the model to study the system response from `r`

to `y`

. Suppose that you also want to study the response of the closed-loop system to a disturbance injected at the plant input. To do so, you can use `connect`

to build the system, inserting an analysis point at the location `u`

.

First create plant and controller models, naming the inputs and outputs as shown in the diagram.

C = pid(2,1); C.InputName = "e"; C.OutputName = "u"; G = zpk([],[-1,-1],1); G.InputName = "u"; G.OutputName = "y";

Create a summing junction that takes the difference between the reference signal `r`

and the plant output `y`

to compute the error signal `e`

.

`Sum = sumblk("e = r - y");`

Combine `C`

, `G`

, and the summing junction to create the aggregate model. Use the `APs`

input argument to `connect`

to insert an analysis point at *u*.

input = "r"; output = "y"; APs = "u"; CL = connect(G,C,Sum,input,output,APs)

Generalized continuous-time state-space model with 1 outputs, 1 inputs, 3 states, and the following blocks: CONNECT_AP1: Analysis point, 1 channels, 1 occurrences. Type "ss(CL)" to see the current value and "CL.Blocks" to interact with the blocks.

This closed-loop model is a generalized state-space (`genss`

) model containing an `AnalysisPoint`

control design block. To see the name of the analysis point channel in `CL`

, use `getPoints`

.

getPoints(CL)

`ans = `*1x1 cell array*
{'u'}

Inserting the analysis point creates a model that is equivalent to the following block diagram, where `AP_u`

designates the `AnalysisPoint`

block with channel name `u`

.

Use the analysis point to extract system responses. For example, the following commands extract the open-loop transfer at `u`

and the closed-loop response at `y`

to a disturbance injected at `u`

.

L = getLoopTransfer(CL,"u",-1); CLdist = getIOTransfer(CL,"u","y");

### Index-Based Interconnection

You can use index-based interconnection to connect model elements without naming all their inputs and outputs. To see how, create a model of the following feedback loop from *r* to *y* using index-based interconnection.

First, create the plant and controller, the elements of the closed-loop system.

C = pid(2,1); G = zpk([],[-1,-1,-5],1);

Use `append`

to group the elements into a single, unconnected aggregate model.

blksys = append(C,G);

`append`

arranges the specified models into a MIMO stacked model, as shown in the following diagram.

To make this stacked model equivalent to the feedback loop, `connect`

must make the following connections:

The input of

`G`

receives the output of`C`

, or`w1`

feeds into`u2`

.The input of

`C`

receives the negative of the output of`G`

, or`-w2`

feeds into`-u1`

.

To instruct `connect`

to make these connections, construct a matrix in which each row specifies one connection or summing junction in terms of the input vector `u`

and output vector `y`

of `blksys`

.

connections = [2 1; % w1 feeds into u2 1 -2]; % -w2 feeds into u1

Finally, specify by index which inputs and outputs of `blksys`

to use for the external inputs and outputs of the closed-loop model.

inputs = 1; % r drives u1 outputs = 2; % y is y2

You can now complete the closed-loop model.

sysc = connect(blksys,connections,inputs,outputs); step(sysc)

### Combine Two Interconnected Models with Analysis Points

This example shows what to expect when combining two models created with `connect`

, each containing analysis points.

Create a model of cascaded feedback loops using these commands.

G1 = tf([1],[1 0]); G1.u = 'OuterError'; G1.y = 'InnerCmd'; G2 = tf([1], [1 1]); G2.u = 'InnerError'; G2.y = 'ActuatorCmd'; SumOuter = sumblk('OuterError = OuterCmd - Outer'); SumInner = sumblk('InnerError = InnerCmd - Inner'); Sys1 = connect(G1,G2,SumOuter,SumInner,{'OuterCmd','Outer','Inner'},'ActuatorCmd', {'InnerError','OuterError'})

Generalized continuous-time state-space model with 1 outputs, 3 inputs, 2 states, and the following blocks: CONNECT_AP1: Analysis point, 2 channels, 1 occurrences. Type "ss(Sys1)" to see the current value and "Sys1.Blocks" to interact with the blocks.

The generalized model `Sys1`

contains a single analysis point block with channels `InnerError`

and `OuterError`

.

Alternatively, you can define inner and outer loops separately.

P1 = connect(G1,SumOuter,{'OuterCmd','Outer'},'InnerCmd','OuterError')

Generalized continuous-time state-space model with 1 outputs, 2 inputs, 1 states, and the following blocks: CONNECT_AP1: Analysis point, 1 channels, 1 occurrences. Type "ss(P1)" to see the current value and "P1.Blocks" to interact with the blocks.

P2 = connect(G2,SumInner,{'InnerCmd','Inner'},'ActuatorCmd','InnerError')

Generalized continuous-time state-space model with 1 outputs, 2 inputs, 1 states, and the following blocks: CONNECT_AP1: Analysis point, 1 channels, 1 occurrences. Type "ss(P2)" to see the current value and "P2.Blocks" to interact with the blocks.

Both `P1`

and `P2`

have an analysis block named `CONNECT_AP1`

. Now combine these two models to create a model `Sys2`

of the cascaded loop.

Sys2 = connect(P1,P2,{'OuterCmd','Outer','Inner'},'ActuatorCmd')

Generalized continuous-time state-space model with 1 outputs, 3 inputs, 2 states, and the following blocks: CONNECT_AP1: Analysis point, 1 channels, 1 occurrences. CONNECT_AP2: Analysis point, 1 channels, 1 occurrences. Type "ss(Sys2)" to see the current value and "Sys2.Blocks" to interact with the blocks.

This model contains two separate analysis point blocks with names `CONNECT_AP1`

and `CONNECT_AP2`

. The `AnalysisPoint`

blocks of `P1`

and `P2`

are automatically renamed to avoid conflict.

## Input Arguments

`sys`

— Dynamic system model or other element to interconnect

LTI model object | control design block | `AnalysisPoint`

block | identified model | sparse model object | time-varying model object | parameter-varying model object | time-varying model object

Dynamic system model or other block-diagram element to interconnect, specified as:

Any numeric LTI model object, such as a

`tf`

,`zpk`

,`ss`

,`frd`

, or`pid`

model object.A generalized or uncertain LTI model, such as a

`genss`

,`genfrd`

,`uss`

(Robust Control Toolbox), and`ufrd`

(Robust Control Toolbox) model.A control design block representing a tunable or uncertain block-diagram element, such as a

`tunablePID`

,`tunableSS`

,`tunableGain`

,`tunableTF`

,`tunableSurface`

,`ultidyn`

(Robust Control Toolbox), or`umargin`

(Robust Control Toolbox) block.An

`AnalysisPoint`

block representing a location in the block diagram at which you want to extract system responses.A summing junction that you create using

`sumblk`

.An identified LTI model, such as an

`idtf`

(System Identification Toolbox),`idss`

(System Identification Toolbox), or`idproc`

(System Identification Toolbox) model.A sparse model, represented by a

`sparss`

or`mechss`

model object.A time-varying or parameter-varying model, represented by an

`ltvss`

or`lpvss`

model object.

`inputs`

— Inputs of combined model

character vector | cell array of character vectors | string | string vector | positive integer | vector of positive integers

Inputs of the combined model, specified as a character vector, cell array of character vectors, string, string vector, positive integer, or vector of positive integers.

For name-based interconnection, provide a character vector, string, cell array of character vectors, or string array listing one or more signals that appear in the

`InputName`

or`OutputName`

property of one or more of the block diagram elements`sys`

`1,...`

`sys`

`N`

. For example,`{'ref','dist','noise'}`

.For index-based interconnection, provide a positive integer or vector of positive integers specifying the index or indices of the inputs of

`blksys`

that you want to be inputs of the aggregate model.

`outputs`

— Outputs of combined model

character vector | cell array of character vectors | string | string vector | positive integer | vector of positive integers

Outputs of the combined model, specified as a character vector, cell array of character vectors, string, string vector, positive integer, or vector of positive integers.

For name-based interconnection, provide a character vector, string, cell array of character vectors, or string array listing one or more signals that appear in the

`InputName`

or`OutputName`

property of one or more of the block diagram elements`sys`

`1,...`

`sys`

`N`

. For example,`{'ref','dist','noise'}`

.For index-based interconnection, provide a positive integer or vector of positive integers specifying the index or indices of the inputs of

`blksys`

that you want to be outputs of the aggregate model.

`APs`

— Locations of interest in the combined model

character vector | cell array of character vectors | string | string vector

Locations (internal signals) of interest in the aggregate model, specified as a
character vector or cell array of character vectors, such as `'X'`

or
`{'AP1','AP2'}`

, or a string or string vector. The resulting model
contains an analysis point at each such location. (See `AnalysisPoint`

). Each location in `APs`

must correspond
to an entry in the `InputName`

or `OutputName`

property of one or more of the block diagram elements
`sys`

`1,...`

`sys`

`N`

.

`blksys`

— Unconnected aggregate model

dynamic system model

Unconnected aggregate model, specified as a dynamic system model that you create
with `append`

. Use `blksys`

for index-based interconnection. The `append`

command stacks the
inputs and outputs of the elements of your block diagram without making any
interconnections between their inputs and outputs. For example, if your block diagram
contains dynamic system models `C`

, `G`

, and
`S`

, create `blksys`

with the following
command:

blksys = append(C,G,S)

Then, specify the interconnections between the inputs and outputs of
`blksys`

using the `connections`

argument. For
an example, see Index-Based Interconnection.

`connections`

— Connections and summing junctions

matrix

Connections and summing junctions of the block diagram, specified as a matrix. Use
`connection`

for index-based interconnection. Each row of
`connections`

specifies one connection or summing junction in terms
of the input vector `u`

and output vector `w`

of the
unconnected aggregate model `blksys`

. For example, the row

[3 2 0 0]

specifies that `w(2)`

, the second output of
`blksys`

, connects into `u(3)`

, the third input of
`blksys`

. The row

[7 2 -15 6]

indicates that the sum `w(2) - w(15) + w(6)`

feeds into
`u(7)`

, the seventh input of `blksys`

.

If you do not specify any connection for a particular input or output,
`connect`

omits that input or output from the aggregate
model.

`opts`

— Additional options for interconnection

`connectOptions`

options set

Additional options for interconnection, specified as an options set that you create
with `connectOptions`

.

By default, the `connect`

command discards states that do not
contribute to the dynamics in the path between the inputs and outputs of the
interconnected system. Use `connectOptions`

to retain these states in
the interconnected model. This option can be useful, for example, when you want to
compute the interconnected system response from known initial state values of the
components.

## Output Arguments

`sysc`

— Interconnected system

state-space model | frequency-response data model

Interconnected system, returned as either a state-space model or frequency-response model. The type of model returned depends on the input models. For example:

Interconnecting numeric LTI models (other than

`frd`

models) returns an`ss`

model.Interconnecting a numeric LTI model with a Control Design Block returns a generalized state-space model. For instance, interconnecting a

`tf`

model with a`tunablePID`

Control Design Block returns a`genss`

model.Interconnecting a numeric LTI model with a sparse model returns a sparse model.

Interconnecting any model with a frequency-response data model returns a frequency response data model.

By default, `connect`

automatically discards states that do not
contribute to the I/O transfer function from the specified inputs to the specified
outputs of the interconnected model. To retain the unconnected states, set the
`Simplify`

option of `connectOptions`

to `false`

. For example:

opt = connectOptions('Simplify',false); sysc = connect(sys1,sys2,sys3,'r','y',opt);

## Version History

**Introduced before R2006a**

### R2024a: Support for connecting multiple interconnected systems with analysis points

You can specify analysis points when modeling block diagrams with `connect`

. When combining the resulting models with any interconnection
function, the software automatically renames these analysis point blocks to avoid conflict.
Before R2024a, such combinations were not possible.

For an example, see Combine Two Interconnected Models with Analysis Points.

### R2015a: Syntax for inserting analysis points

You can now specify analysis point locations using the `APs`

input
argument, using the following syntax.

sysc = connect(sys1,sys2,...,sysN,inputs,outputs,APs)

For an example, see Feedback Loop with Analysis Point.

### R2013b: Option to retain unconnected states

By default, the `connect`

command discards states that do not
contribute to the dynamics in the path between the inputs and outputs of the interconnected
system. You can now use the `opts`

input argument to retain such
unconnected states. This option can be useful, for example, when you want to compute the
interconnected system response from known initial state values of the components. Create
`opts`

with `connectOptions`

.

### R2013b: `connect`

returns state-space or frequency response data model

`connect`

always returns a state-space model, such as an
`ss`

, `genss`

, or `uss`

model,
unless one or more of the input models is a frequency response data model. In that case,
`connect`

returns a frequency response data model, such as an
`frd`

or `genfrd`

model. In previous releases,
`connect`

returned a `tf`

or
`zpk`

model when all input models were `tf`

or
`zpk`

models.

## MATLAB-Befehl

Sie haben auf einen Link geklickt, der diesem MATLAB-Befehl entspricht:

Führen Sie den Befehl durch Eingabe in das MATLAB-Befehlsfenster aus. Webbrowser unterstützen keine MATLAB-Befehle.

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

## How to Get Best Site Performance

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

### Americas

- América Latina (Español)
- Canada (English)
- United States (English)

### Europe

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