Main Content

create

Create object in connected data source

Since R2024a

    Description

    example

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

    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.

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

    example

    dataObj = create(connectionObj, 'Enum', enumerals, 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 enum type in a data source. You cannot create an enum type in a data source by using dot notation or the set function.

    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 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"], EnumValue=[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 array.

    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