Main Content

Simulink.dictionary.archdata.Constant

Store constant values in Architectural Data section of data dictionaries

Since R2023b

    Description

    Use a Simulink.dictionary.archdata.Constant object to represent a constant in the Architectural Data section of a data dictionary.

    Creation

    You can add a Simulink.dictionary.archdata.Constant object to a data dictionary in two ways.

    • Interactively create a Simulink.dictionary.archdata.Constant object by using the Architectural Data Editor.

    • Programmatically create a Simulink.dictionary.archdata.Constant object by using the addConstant function.

    archDataObj = Simulink.dictionary.archdata.create("dataDictionary.sldd");
    constant = addConstant(archDataObj,"myConst",Value=4)
    constant = 
    
      Constant with properties:
    
               Name: 'myConst'
              Value: 4
           DataType: 'double'
        Description: ''
              Owner: [1×1 Simulink.dictionary.ArchitecturalData]
    

    Properties

    expand all

    Name of the constant object, specified as a character vector or string scalar.

    Example: addConstant(archDataObj,"myConst")

    Data Types: char | string

    Value owned by the constant object, specified as any numeric value.

    Example: addConstant(archData,"myConstant",Value=2)

    Example: addConstant(archData,"myConstant",Value=uint32(16))

    This property is read-only.

    Data type of constant object, represented as 'double'. To change the underlying data type of the constant object, see Set Underlying Data Type of Constant Object in Architectural Data Section of Simulink Data Dictionary.

    Description of the constant object, specified as a character vector.

    Example: 'Constant representing maximum RPM.'

    Data Types: char

    Simulink.dictionary.ArchitecturalData object that contains the constant object.

    Example: Owner: [1×1 Simulink.dictionary.ArchitecturalData]

    Object Functions

    moveToDictionaryMove architectural data of Simulink data dictionary to another data dictionary
    moveToDesignDataMove objects in Architectural Data section of Simulink data dictionary to Design Data section of the same data dictionary
    showView architectural data of Simulink data dictionary in Architectural Data Editor
    destroyDelete data element and remove from data interface

    Examples

    collapse all

    To add a constant to the data dictionary you use the addConstant function. For more examples of architectural data management workflows and related functions, see Store Data in Architectural Data Section Programmatically.

    Create or open a data dictionary.

    dictName = "myDictionary.sldd";
    archData = Simulink.dictionary.archdata.create(dictName);
    

    Add a constant by using the addConstant function. Specify the constant name, and its value as a 16 bit integer variable.

    myConst = addConstant(archData,"myConstant",Value=int16(12))
    myConst = 
    
      Constant with properties:
    
               Name: 'myConstant'
              Value: 12
           DataType: 'int16'
        Description: ''
              Owner: [1×1 Simulink.dictionary.ArchitecturalData]
    

    The DataType property of a Simulink.dictionary.archdata.Constant object is derived from the data type of its value. To change the data type, assign a new value that uses the desired data type by using data type conversion functions, such as uint8 and int16. For more information about integer classes and their conversion functions, see Integers.

    Create or open a data dictionary.

    dictName = "myDictionary.sldd";
    archData = Simulink.dictionary.archdata.create(dictName);
    

    When you add a constant to the Architectural Data section, you can set the data type of an existing constant by converting the data type of the owned value.

    minSpeed = addConstant(archData,"MinimumSpeedLimit",Value=40);
    set(minSpeed,Value=int8(40));
    minSpeed
    minSpeed = 
    
      Constant with properties:
    
               Name: 'MinimumSpeedLimit'
              Value: 40
           DataType: 'int8'
        Description: ''
              Owner: [1×1 Simulink.dictionary.ArchitecturalData]

    You can also create a numeric variable of a specified data type and then set the value of the constant object to that numeric variable.

    rpm = int16(40);
    maxEngineRPM = addConstant(archData,"MaxEngineRPM",Value=rpm)
    maxEngineRPM = 
    
      Constant with properties:
    
               Name: 'MaxEngineRPM'
              Value: 40
           DataType: 'int16'
        Description: ''
              Owner: [1×1 Simulink.dictionary.ArchitecturalData]

    Version History

    Introduced in R2023b