Main Content

Simulink.data.connect

Create Simulink.data.DataConnection object for data source

Since R2024a

    Description

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

    example

    connectionObj = Simulink.data.connect(dataSource,TabComplete=tcOption) specifies whether tab completion for the object includes methods, variables, or both methods and variables. 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 might 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.

    example

    Examples

    collapse all

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

    Since R2024b

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

    matFile = Simulink.data.connect("myMatFile.mat")
    matFile = 
    
    DataConnection to myMatFile.mat

    Create a data connection to the model workspace for model vdp.

    mw = Simulink.data.connect("vdp.slx")
    
    mw = 
    
    DataConnection to vdp.slx

    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, including file extension

    • Base workspace — "base workspace"

    Example: "myDictionary.sldd"

    Example: "myMatFile.mat"

    Example: "vdp.slx"

    Example: "base workspace"

    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".

    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