主要内容

Simulink.data.connect

R2026b

Create Simulink.data.DataConnection object for data source

Since R2024a

    Description

    connectionObj = Simulink.data.connect(dataSource) creates a data connection object for the base workspace, model workspace, MAT file, or Design Data section of a data dictionary. The function returns a Simulink.data.DataConnection object representing the connection to the data source.

    example

    connectionObj = Simulink.data.connect(dataSource,Name=Value) specifies options using one or more name-value arguments in addition to the input argument in the previous syntax. For example, to create a data connection object for the Configurations section of a data dictionary or model file, set Section to "Configurations".

    example

    Examples

    collapse all

    Create a data dictionary.

    Simulink.data.dictionary.create("myDictionary.sldd");
    

    Create a connection object to interact with the Design Data section of the dictionary.

    dd = Simulink.data.connect("myDictionary.sldd")
    
    dd = 
    
    DataConnection to myDictionary.sldd

    Create a separate connection to interact with the Configurations section of the dictionary

    cfg = Simulink.data.connect("myDictionary.sldd",Section="Configurations");
    
    cfg = 
    
    DataConnection to myDictionary.sldd : Configurations

    Create a data connection to the MAT file myMatFile.mat.

    matFile = Simulink.data.connect("myMatFile.mat")
    matFile = 
    
    DataConnection to myMatFile.mat
    mw = Simulink.data.connect("vdp.slx")
    
    mw = 
    
    DataConnection to vdp.slx
    mw_cfg = Simulink.data.connect("vdp.slx",Section="Configurations")
    
    mw_cfg = 
    DataConnection to vdp.slx : Configurations

    Create a data connection to the base workspace and configure tab completion to show only variables in the connected data source.

    bw = Simulink.data.connect("base workspace",TabComplete="Vars")
    
    bw = 
    
    DataConnectionTCV to base workspace

    Input Arguments

    collapse all

    Name of data source, specified as a string or character vector. Data source can be a data dictionary, a MAT file, a model workspace, or the base workspace.

    • Data dictionary — Name of data dictionary, including file extension

    • MATLAB® file — Name of MAT file, including file extension (since R2024b)

    • Model workspace — Name of model, with or without file extension

    • Base workspace — "base workspace"

    Example: "myDictionary.sldd"

    Example: "myMatFile.mat"

    Example: "vdp.slx" or "vdp"

    Example: "base workspace"

    Name-Value Arguments

    collapse all

    Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

    Example: Simulink.data.connect("vdp.slx",Section="Design Data",TabComplete="Vars") creates a connection object to the Design Data section of a data dictionary and sets tab completion to display variables available in the data source.

    Tab completion preference, specified as "Methods", "Vars", or "All". By default, tab completion displays the methods available for the connected data source. To configure tab completion to display variables available in the data source, specify "Vars". To configure tab completion to display both methods and variables for the data source, specify "All". Once you create a connection to the data source, you cannot change your tab completion preference.

    If you change the contents of the data source outside of the data connection object (through a user interface, data-source-specific functions, or other data connection), variables listed by tab completion can be out of sync with the list of variables in the data source. To update the variables in the tab completion list, use the object function syncTabComplete:

    syncTabComplete(connectionObj);
    

    For data dictionaries and model workspaces, the section of the data source to connect to, specified as "Design Data" or "Configurations".

    A data connection object can connect to only one section of a data source. To interact with both the Design Data and Configurations sections of a data source, create a separate connection object for each section.

    Output Arguments

    collapse all

    Connection to data source, returned as a Simulink.data.DataConnection object. If you specify tcOptions as either "Vars" or "All", the connection is returned as a Simulink.data.DataConnectionTCV or Simulink.data.DataConnectionTCMV object, respectively. Simulink.data.DataConnectionTCV and Simulink.data.DataConnectionTCMV are both inherited from Simulink.data.DataConnection and support the same methods.

    Version History

    Introduced in R2024a

    expand all