connect
Description
connects the components, pipelines, and ports in newPipeline = connect(pipeline,connections)pipeline as indicated
by the directed edges in connections. All the connections must be
valid, or none are made.
connect guarantees that the resulting pipeline
newPipeline has no cycles or duplicate edges. However, the function
does not guarantee that the pipeline can be executed after the connections are made.
Examples
Create a pipeline with components for data preprocessing. First, connect the
normalizer and oneHotEncoder components in
parallel to create pipeline. Then, combine
removeMissing, pipeline, and
pcaTransformer in series to create
preprocessingPipeline. View the data preprocessing pipeline.
removeMissing = observationRemoverComponent; normalizer = normalizerComponent; oneHotEncoder = oneHotEncoderComponent; pcaTransformer = pcaComponent; pipeline = parallel(normalizer,oneHotEncoder); preprocessingPipeline = series(removeMissing,pipeline,pcaTransformer); view(preprocessingPipeline)

Remove the oneHotEncoder component from the pipeline.
preprocessingPipeline = remove(preprocessingPipeline,"OneHotEncoder");
view(preprocessingPipeline)
Next, remove the normalizer component from the pipeline.
preprocessingPipeline = remove(preprocessingPipeline,"Normalizer");
view(preprocessingPipeline)
The remaining two components are not connected.
Connect the components and view the pipeline. The number of outputs in
removeMissing is not equivalent to the number of inputs in
pcaTransformer. So, you must specify the input and output ports to
connect. To see the names of the inputs and outputs of a component, index into the
component, for example,
preprocessingPipeline.Components.ObservationRemover.
preprocessingPipeline = connect(preprocessingPipeline, ... ["ObservationRemover/DataOut1","PCA/DataIn"]); view(preprocessingPipeline)

Create a pipeline object.
pipeline = LearningPipeline
pipeline =
LearningPipeline with properties:
Name: "defaultName"
Inputs: [0×0 string]
InputTags: []
Outputs: [0×0 string]
OutputTags: []
Components: struct with 0 entries
Connections: [0×2 table]
HasLearnables: false
Show summary of the componentsCreate a component to remove missing values and another to perform multiclass classification. Add the components to the pipeline, and then view the pipeline.
removeMissing = observationRemoverComponent; ecoc = classificationECOCComponent; newPipeline = add(pipeline,removeMissing,ecoc); view(newPipeline)

The pipeline does not have the same number of ports as the inputs and outputs of the
removeMissing and ecoc components.
Add corresponding ports to the pipeline. View the pipeline.
newPipeline.Inputs = ["XIn","YIn"]; newPipeline.Outputs = ["Predictions","Scores","Loss"] view(newPipeline)
newPipeline =
LearningPipeline with properties:
Name: "defaultName"
Inputs: ["XIn" "YIn"]
InputTags: [0 0]
Outputs: ["Predictions" "Scores" "Loss"]
OutputTags: [0 0 0]
Components: struct with 2 entries
Connections: [0×2 table]
HasLearnables: true
HasLearned: false
Show summary of the components
The software does not automatically connect components or ports.
Connect the two components and the new ports. View the final pipeline.
finalPipeline = connect(newPipeline, ... ["XIn","ObservationRemover/DataIn1", ... "YIn","ObservationRemover/DataIn2"]); finalPipeline = connect(finalPipeline, ... ["ObservationRemover/DataOut1","ClassificationECOC/Predictors", ... "ObservationRemover/DataOut2","ClassificationECOC/Response"]); finalPipeline = connect(finalPipeline, ... ["ClassificationECOC/Predictions","Predictions", ... "ClassificationECOC/Scores","Scores", ... "ClassificationECOC/Loss","Loss"]); view(finalPipeline)

Input Arguments
Existing pipeline, specified as a LearningPipeline object.
Names of the ports to connect, specified as a string array or cell array of
character vectors, indicating ordered pairs of sources and destinations, or a table with
two columns (Source and Destination). The format
of connections must be the same as the format of the
Connections property of the pipeline. You can find the name of a
component in a pipeline by using the describe
object function (for example, describe(pipeline)).
describe also displays the component input and output port
names.
Data Types: string | cell | table
Output Arguments
Pipeline with new connections, returned as a LearningPipeline
object.
More About
You can specify component ports as string scalars or character vectors of the form
componentName/portName, where componentName is the
name of the component, and portName is the name of the port.
When specifying ports of the existing pipeline (pipeline), specify
the port name only.
Version History
Introduced in R2026a
See Also
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.
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)