Main Content

create

Create object in connected data source

Since R2024a

    Description

    dataObj = create(connectionObj,varType,varName) creates and returns a new object with type varType and name varName in the connected data source connectionObj.

    If a data connection can see multiple data sources (for example, a data dictionary and its referenced dictionaries), the function creates the object in the directly connected data source.

    Simulink® reports an error if the varName already exists in the connected data source or if the data source does not support the varType.

    example

    dataObj = create(connectionObj,"Bus",BusElementNames=busElementNames) creates a Simulink.Bus object with the specified Simulink.BusElement objects.

    dataObj = create(connectionObj,"Enum",Enumerals=enumerals,EnumValues=enumValues) creates a Simulink.data.dictionary.EnumTypeDefinition object with the specified enumeration members and member values. This is the only way to create a new enumerated type in a data source. You cannot create an enumerated type in a data source by using dot notation or the set function.

    example

    Examples

    collapse all

    Create a data connection to the model workspace for model myModel. Then create a Simulink.Parameter object in the workspace.

    mw = Simulink.data.connect("myModel.slx")
    paramObj = create(mw,"Parameter","newParam");

    Create a data connection to the MAT file myMatFile.mat and then create a variable newVar in the MAT file.

    matFile = Simulink.data.connect("myMatFile.mat")
    varObj = create(matFile,"Variable","newVar");

    Create a data connection to a data dictionary. Then create a Simulink.data.dictionary.EnumTypeDefinition in the Design Data section of the dictionary.

    dd = Simulink.data.connect("myDictionary.sldd");
    daobj = create(dd,"Enum","mColors",Enumerals=["Red","Green","Blue"],EnumValues=[1 2 3])
    daobj = 
    
       Simulink.data.dictionary.EnumTypeDefinition
          Red
          Green
          Blue
    

    Input Arguments

    collapse all

    Connection to data source, specified as a Simulink.data.DataConnection object.

    Variable type to create in the connected data source, specified by a string expression that is a valid data object constructor. For data objects in the Simulink package, you can specify the short name or the fully qualified object name (for example 'Parameter' or 'Simulink.Parameter').

    Example: 'Variable'

    Example: 'Bus' or 'Simulink.Bus'

    Example: 'fixdt(1,16,12)'

    Variable name for the new object, specified as a string or character vector.

    Example: 'myBus'

    Bus element objects used to create the Simulink.Bus object, specified as a string array or cell array of character vectors.

    Enumeration members, specified as a string array or cell array of character vectors.

    Enumeration member values, specified as a vector of integers matching the dimension of enumerals.

    Output Arguments

    collapse all

    Data object created in the connected data source.

    Version History

    Introduced in R2024a