主要内容

getTunableParameterInitialValue

Class: coder.codedescriptor.CodeDescriptor
Namespace: coder.codedescriptor

Return initial value of tunable parameter in generated code as string

Since R2026a

Syntax

initialCodeValueStr = getTunableParameterInitialValue(codeDescObj,parameterDataInterface)

Description

initialCodeValueStr = getTunableParameterInitialValue(codeDescObj,parameterDataInterface) returns the initial value of a parameter described by the data interface object parameterDataInterface.

Input Arguments

expand all

coder.codedescriptor.CodeDescriptor object for which you want to retrieve the information about the generated code.

Data Types: coder.codedescriptor.CodeDescriptor

coder.codedescriptor.DataInterface object representing a tunable parameter for which you want to retrieve initial values in the generated code. You can create these objects by calling getDataInterfaces('Parameters') on codeDescObj.

Data Types: coder.codedescriptor.DataInterface

Output Arguments

expand all

Initial value of the parameter described by parameterDataInterface, returned as a character vector. The format of the returned value matches that of the generated code.

Data Types: char

Limitations

The following parameters are unsupported:

  • Images

  • Structured parameters, such as arrays and buses, that contain nonfinite values

Examples

expand all

  1. Open the model.

    openExample('CustomCodeComments')
  2. Configure block parameters to be tunable in the generated code.

    set_param('CustomCodeComments','DefaultParameterBehavior','Tunable')

  3. Build the model.

    slbuild('CustomCodeComments')

  4. Create a coder.codedescriptor.CodeDescriptor object for the required model.

    codeDescObj = coder.getCodeDescriptor('CustomCodeComments')
    

  5. Get parameter data interfaces in the generated code.

    dataInterfaces = getDataInterfaces(codeDescObj,'Parameters');
  6. Return the properties of the second data interface object, describing parameters for the Constant block in the generated code.

    dataInterface = dataInterfaces(2)
    ans = 
    
      DataInterface with properties:
                  Type: [1×1 coder.descriptor.types.Type]
                   SID: ''
         GraphicalName: 'const_val'
           VariantInfo: [1×0 coder.descriptor.VariantInfo]
        Implementation: [1×1 coder.descriptor.DataImplementation]
                Timing: [1×0 coder.descriptor.TimingInterface]
                  Unit: ''
                 Range: [1×0 coder.descriptor.Range]
  7. Return the initial parameter values for the Constant block.

    codeDescObj.getTunableParameterInitialValue(dataInterface)
    ans =
        '{ 1.0, 2.0, 3.0, 4.0 }'

Version History

Introduced in R2026a