Main Content

getElement

Get data element from data interface

Since R2023b

    Description

    dataElementObj = getElement(dataInterfaceObj,elementName) returns the data element object with the name elementName contained in the data interface specified by dataInterfaceObj.

    example

    Examples

    collapse all

    This example shows how to add, get, and remove data elements from a data interface.

    Use the Simulink.dictionary.archdata.open function to open an existing data dictionary. This creates a Simulink.dictionary.ArchitecturalData object, archDataObj.

    archDataObj = Simulink.dictionary.archdata.open("myInterfaceDict.sldd")
    archDataObj = 
    
      ArchitecturalData with properties:
    
        DictionaryFileName: 'myInterfaceDict.sldd'
                Interfaces: [1×1 Simulink.dictionary.archdata.DataInterface]
                 DataTypes: [0×0 Simulink.dictionary.archdata.DataType]
                 Constants: [0×0 Simulink.dictionary.archdata.Constant]
    

    The data dictionary contains one data interface definition.

    interfaceObj = getInterface(archDataObj,"DataInterface")
    interfaceObj = 
    
      DataInterface with properties:
    
               Name: 'DataInterface'
        Description: ''
           Elements: [0×0 Simulink.dictionary.archdata.DataElement]
              Owner: [1×1 Simulink.dictionary.ArchitecturalData]

    Data interfaces are composed of data elements that describe parts of a data interface. This interface definition contains two data elements.

    getElement(interfaceObj,"Element1")
    ans = 
    
      DataElement with properties:
    
               Name: 'Element1'
               Type: [1×1 Simulink.dictionary.archdata.ValueType]
        Description: ''
         Dimensions: '1'
              Owner: [1×1 Simulink.dictionary.archdata.DataInterface]
    getElement(interfaceObj,"Element2")
    ans = 
    
      DataElement with properties:
    
               Name: 'Element2'
               Type: [1×1 Simulink.dictionary.archdata.ValueType]
        Description: ''
         Dimensions: '1'
              Owner: [1×1 Simulink.dictionary.archdata.DataInterface]

    Use the addElement function to add a new data element to the data interface.

    dataElem1 = addElement(interfaceObj,"element3")
    dataElem1 = 
    
      DataElement with properties:
    
               Name: 'element3'
               Type: [1×1 Simulink.dictionary.archdata.ValueType]
        Description: ''
         Dimensions: '1'
              Owner: [1×1 Simulink.dictionary.archdata.DataInterface]

    You can get an existing data element using the getElement function.

    dataElem3 = getElement(interfaceObj,"element3")
    dataElem3 = 
    
      DataElement with properties:
    
               Name: 'element3'
               Type: [1×1 Simulink.dictionary.archdata.ValueType]
        Description: ''
         Dimensions: '1'
              Owner: [1×1 Simulink.dictionary.archdata.DataInterface]

    Remove a data element from an interface using the removeElement function.

    removeElement(interfaceObj,"element3")

    Input Arguments

    collapse all

    Data interface object containing the data element, specified as a Simulink.dictionary.archdata.DataInterface object.

    Name of the data element in the dataInterfaceObj object, specified as a character vector or string scalar.

    Output Arguments

    collapse all

    Data element object, specified as a Simulink.dictionary.archdata.DataElement object.

    Version History

    Introduced in R2023b