주요 콘텐츠

replace

Replace existing pipeline component with new component

Since R2026a

    Description

    newPipeline = replace(pipeline,existingName,newComponent) replaces the existingName component in pipeline with the component in newComponent. The function connects the new component in the same way as the existing component it replaces.

    In particular, the inputs of the new component connect to the same ports to which the inputs of the existing component were connected. The outputs of the new component are similarly connected to the ports that received outputs from the existing component.

    Connections are made strictly by port order. That is, the first input port of the new component connects to the port that fed data to the first input port of the existing component, and likewise for the output ports.

    You can specify a new component with fewer (but not more) inputs or outputs than the component it replaces.

    example

    [newPipeline,newName] = replace(pipeline,existingName,newComponent) additionally returns the name of the new component (newName). Because component names must be unique within a pipeline, the function might rename the component by adding a numeric suffix (for example, _1).

    Examples

    collapse all

    Create a pipeline with four components.

    normalizer = normalizerComponent;
    oneHotEncoder = oneHotEncoderComponent;
    pcaTransformer = pcaComponent;
    ecoc = classificationECOCComponent;
    pipeline = series(parallel(normalizer,oneHotEncoder), ...
        pcaTransformer,ecoc);

    To view the pipeline, specify view(pipeline).

    Replace ecoc with a classification k-nearest neighborhood component. In the call to replace, specify the name of the ecoc component as stored in the Name property.

    knn = classificationKNNComponent;
    ecoc.Name
    ans = 
    
        "ClassificationECOC"
    newPipeline = replace(pipeline,"ClassificationECOC",knn);

    To view the updated pipeline, specify view(newPipeline).

    Because knn has the same inputs and outputs as ecoc, the replace function automatically connects the corresponding inputs and outputs.

    Input Arguments

    collapse all

    Existing pipeline, specified as a LearningPipeline object.

    Name of the component to replace in the existing pipeline, specified as a character vector or string scalar. You can find the name of a component in its Name property.

    Data Types: char | string

    New component to replace the existingName component, specified as a learning component object. For a list of learning component objects, see pipe.

    Output Arguments

    collapse all

    Pipeline with the new component, returned as a LearningPipeline object.

    Name of the new component, returned as a string scalar.

    Tips

    • replace combines the functionality of add, remove, and connect, providing a shortcut for a common pipeline editing operation. For more flexibility than replace provides, consider calling add, remove, and connect separately.

    Version History

    Introduced in R2026a