主要内容

functionComponent

Pipeline component for custom function

Since R2026a

    Description

    functionComponent is a pipeline component that performs a custom function. During the learn and run phases, the component executes the custom function.

    Creation

    Description

    component = functionComponent(fun) creates a pipeline component using the custom function fun.

    component = functionComponent(fun,numInputs,numOutputs) sets the number of input and output ports to numInputs and numOutputs, respectively.

    example

    component = functionComponent(___,Name=Value) sets Properties using one or more name-value arguments in addition to any of the input argument combinations in previous syntaxes. For example, you can specify the input tags using the InputTags name-value argument.

    Input Arguments

    expand all

    Function for component, specified as a function handle. When selecting a custom function, choose one that works well with table data types. If you specify a function that accepts a variable number of inputs, you must also specify the expected number of function inputs using the numInputs argument.

    Data Types: function_handle

    Number of input ports, specified as a positive integer scalar. If you specify numInputs, Inputs and InputTags will each have numInputs elements.

    Data Types: single | double

    Number of output ports, specified as a positive integer scalar. If you specify numOutputs, Outputs and OutputTags will each have numOutputs elements.

    Data Types: single | double

    Properties

    expand all

    Structural Parameters

    The software sets structural parameters when you create the component. You cannot modify structural parameters after creating the component.

    This property is read-only after the component is created.

    Custom function as specified by fun, specified as a function handle. During execution, the component applies FunctionHandle to the input data.

    Data Types: function_handle

    Component Properties

    The software sets component properties when you create the component. You can modify the component properties (excluding HasLearnables and HasLearned) using dot notation at any time. You cannot modify the HasLearnables and HasLearned properties directly.

    Component identifier, specified as a character vector or string scalar.

    Example: c = functionComponent(@fun,Name="NewMetric")

    Example: c.Name = "CustomComponent"

    Data Types: char | string

    Names of the input ports, specified as a character vector, string array, or cell array of character vectors.

    If you pass numInputs during creation, the default value is ["In1","In2",...,"Inn"] where n is the number of inputs specified by numInputs. Otherwise, n is the number of input arguments to fun.

    Example: c = functionComponent(@fun,Inputs=["X","Y"])

    Example: c.Inputs = ["X1","Y1"]

    Data Types: char | string | cell

    Names of the output ports, specified as a character vector, string array, or cell array of character vectors.

    If you pass numOutputs during creation, the default value is ["Out1","Out2",...,"Outn"] where n is the number of outputs specified by numOutputs. Otherwise, the default value is "Out1".

    Example: c = functionComponent(@fun,Outputs=["newX","newY"])

    Example: c.Outputs = ["X","Y"]

    Data Types: char | string | cell

    Tags that enable the automatic connection of the component inputs with other components or pipelines, specified as a nonnegative integer vector. If you specify InputTags, the number of tags must match the number of inputs in Inputs.

    If you pass numInputs during creation, the default value is zeros(1,n), where n is the number of inputs specified by numInputs. Otherwise, n is the number of input arguments to fun.

    Example: c = functionComponent(@fun,InputTags=[1 0])

    Example: c.InputTags = [1 2]

    Data Types: single | double

    Tags that enable the automatic connection of the component outputs with other components or pipelines, specified as a nonnegative integer vector. If you specify OutputTags, the number of tags must match the number of outputs in Outputs.

    If you pass numOutputs during creation, the default value is zeros(1,n), where n is the number of outputs specified by numOutputs. Otherwise, the default is 0.

    Example: c = functionComponent(@fun,OutputTags=[1 0])

    Example: c.OutputTags=[1 2]

    Data Types: single | double

    This property is read-only.

    Indicator for the learnables, returned as 0 (false). A value of 0 indicates that the component does not contains learnables.

    Data Types: logical

    This property is read-only.

    Indicator showing the learning status of the component, returned as 0 (false).

    Data Types: logical

    Object Functions

    learnInitialize and evaluate pipeline or component
    runExecute pipeline or component for inference after learning
    resetReset pipeline or component
    seriesConnect components in series to create pipeline
    parallelConnect components or pipelines in parallel to create pipeline
    viewView diagram of pipeline inputs, outputs, components, and connections

    Examples

    collapse all

    Create a functionComponent pipeline component. To compute feature means, pass a function handle to the mean function. Because mean can accept a variable number of inputs, you must specify one component input.

    component = functionComponent(@mean,1)
    component = 
      functionComponent with properties:
    
                  Name: "Function"
                Inputs: "In1"
             InputTags: 0
               Outputs: "Out1"
            OutputTags: 0
    
       
    Structural Parameters (locked)
        FunctionHandle: @mean
    
    
    Show all parameters

    Read the fisheriris data set into a table. Store the predictor and response data in the tables X and Y, respectively.

    fisheriris = readtable("fisheriris.csv");
    X = fisheriris(:,1:end-1);
    Y = fisheriris(:,end);

    Use the run object function to compute the mean values of the features in the predictor data.

    meanVal = run(component,X)
    meanVal = 
        SepalLengthCustomTransformed    SepalWidthCustomTransformed    PetalLengthCustomTransformed    PetalWidthCustomTransformed
        ____________________________    ___________________________    ____________________________    ___________________________
    
                   5.8433                         3.0573                          3.758                          1.1993           

    Version History

    Introduced in R2026a