Main Content

getElement

Get data element from data interface

Since R2022b

    Description

    example

    dataElementObj = getElement(dataInterfaceObj,elementName) returns the Simulink.interface.dictionary.DataElement object with the name elementName contained in the Simulink.interface.dictionary.DataInterface object dataInterfaceObj.

    Examples

    collapse all

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

    Open an existing interface dictionary. This creates a Simulink.interface.Dictionary object, interfaceDictObj.

    interfaceDictObj = Simulink.interface.dictionary.open('myInterfaceDict.sldd')
    interfaceDictObj = 
      ArchitecturalData with properties:
    
        DictionaryFileName: 'myInterfaceDict.sldd'
                Interfaces: [1x1 Simulink.dictionary.archdata.DataInterface]
                 DataTypes: [0x0 Simulink.dictionary.archdata.DataType]
                 Constants: [0x0 Simulink.dictionary.archdata.Constant]
    
    

    This interface dictionary contains one data interface definition.

    interfaceObj = interfaceDictObj.Interfaces
    interfaceObj = 
      DataInterface with properties:
    
               Name: 'interface1'
        Description: ''
           Elements: [1x2 Simulink.dictionary.archdata.DataElement]
              Owner: [1x1 Simulink.dictionary.ArchitecturalData]
    
    

    Data interfaces are composed of data elements which describe portions of a data interface. This interface definition contains two data elements.

    interfaceObj.Elements(1)
    ans = 
      DataElement with properties:
    
               Name: 'element1'
               Type: [1x1 Simulink.dictionary.archdata.ValueType]
        Description: ''
         Dimensions: '1'
              Owner: [1x1 Simulink.dictionary.archdata.DataInterface]
    
    
    interfaceObj.Elements(2)
    ans = 
      DataElement with properties:
    
               Name: 'element2'
               Type: [1x1 Simulink.dictionary.archdata.ValueType]
        Description: ''
         Dimensions: '1'
              Owner: [1x1 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: [1x1 Simulink.dictionary.archdata.ValueType]
        Description: ''
         Dimensions: '1'
              Owner: [1x1 Simulink.dictionary.archdata.DataInterface]
    
    

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

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

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

    removeElement(interfaceObj, 'element3')

    Input Arguments

    collapse all

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

    Name of the data element to return from dataInterfaceObj, specified as a character vector or string scalar.

    Output Arguments

    collapse all

    Data element, returned as a Simulink.interface.dictionary.DataElement object.

    Version History

    Introduced in R2022b

    expand all