Main Content

Parameter Functions

LibBlockMatrixParameter

LibBlockMatrixParameter(param, rucv, rlcv, ridx, cucv, clcv, cidx) returns a matrix parameter for a block, given the row and column user control variables (rucv, cucv), loop control variables (rlcv, clcv), and indices (ridx, cidx). Generally, blocks should use LibBlockParameter. If you have a matrix parameter, you should write it as a column-major vector and access it via LibBlockParameter.

Note

Loop rolling is currently not supported, and will generate an error if requested (i.e., if either rlcv or clcv is not equal to "").

The row and column index arguments are similar to the arguments for LibBlockParameter. The column index (cidx) is overloaded to handle complex numbers.

See LibBlockMatrixParameter in paramlib.tlc.

LibBlockMatrixParameterAddr

LibBlockMatrixParameterAddr(param, rucv, rlcv, ridx, cucv, clcv, cidx) returns the address of a matrix parameter.

Note

LibBlockMatrixParameterAddr returns the address of a matrix parameter. Loop rolling is not supported (i.e., rlcv and clcv should both be an empty string).

See LibBlockMatrixParameterAddr in paramlib.tlc.

LibBlockMatrixParameterBaseAddr

LibBlockMatrixParameterBaseAddr(param) returns the base address of a matrix parameter.

See LibBlockMatrixParameterBaseAddr in paramlib.tlc.

LibBlockParamSetting

LibBlockParamSetting(bType, psType) returns the string of a specified parameter setting for a specified block type. If you pass an empty block type into this function, the parameter setting will be assumed to be in the ParamSettings record of the block. If a nonempty block type is passed into the function, the parameter settings will be assumed to be in the %<Btype>ParamSettings record of that block.

See LibBlockParamSetting in paramlib.tlc.

LibBlockParameter

Based on the parameter reference (param), the user control variable (ucv), the loop control variable (lcv), the signal index (sigIdx), and the state of parameter inlining, LibBlockParameter(param, ucv, lcv, sigIdx) returns a reference to a block parameter. The returned value is a valid rvalue (right-side value for an expression). For example,

CaseFunction CallCan Produce

1

LibBlockParameter(Gain, "i", lcv, sigIdx)rtP.blockname[i]

2

LibBlockParameter(Gain, "i", lcv, sigIdx)rtP.blockname

3

LibBlockParameter(Gain, "", lcv, sigIdx)p_Gain[i]

4

LibBlockParameter(Gain, "", lcv, sigIdx) p_Gain

5

LibBlockParameter(Gain, "", lcv, sigIdx)4.55

6

LibBlockParameter(Gain, "", lcv, sigIdx)rtP.blockname.re

7

LibBlockParameter(Gain, "", lcv, sigIdx)rtP.blockname.im

To illustrate the basic workings of LibBlockParameter, assume a noncomplex vector signal where Gain[0]=4.55:

LibBlockParameter(Gain, "", "i", 0)
CaseRollingInline ParameterTypeResultRequired in Memory

1

0

Yes

Scalar

4.55

No

2

1

Yes

Scalar

4.55

No

3

0

Yes

Vector

4.55

No

4

1

Yes

Vector

p_Gain[i]

Yes

5

0

No

Scalar

rtP.blk.Gain

No

6

0

No

Scalar

rtP.blk.Gain

No

7

0

No

Vector

rtP.blk.prm[0]

No

8

0

No

Vector

p.Gain[i]

Yes

Note Case 4. Even though Inline Parameter is Yes, the parameter must be placed in memory (RAM), because it is accessed inside a for loop.

Note

LibBlockParameter also supports expressions when used with inlined parameters and parameter tuning.

For example, if the parameter field had the MATLAB® expression '2*a', LibBlockParameter would return the C expression '(2*a)'. The list of functions supported by LibBlockParameter is determined by the functions FcnConvertNodeToExpr and FcnConvertIdToFcn. To enhance functionality, augment or update either of these functions.

Note that certain types of expressions are not supported, such as x*y where both x and y are nonscalar expressions.

See the documentation about tunable parameters for more details on the exact functions and syntax that are supported.

Warning

Do not use LibBlockParameter to access the address of a parameter, or you may might erroneously reference a number (i.e., &4.55) when the parameter is inlined. You can avoid this situation by using LibBlockParameterAddr.

See LibBlockParameter in paramlib.tlc.

LibBlockParameterAddr

LibBlockParameterAddr(param, ucv, lcv, idx) returns the address of a block parameter.

Using LibBlockParameterAddr to access a parameter when the global InlineParams variable is equal to 1 will cause the variable to be declared const in RAM instead of being inlined.

Accessing the address of an expression when the expression has multiple tunable/rolled variables in it will result in an error.

See LibBlockParameterAddr in paramlib.tlc.

LibBlockParameterBaseAddr

LibBlockParameterBaseAddr(param) returns the base address of a block parameter.

Using LibBlockParameterBaseAddr to access a parameter when the global InlineParams variable is equal to one will cause the variable to be declared const in RAM instead of being inlined.

Accessing the address of an expression when the expression has multiple tunable/rolled variables in it will result in an error.

See LibBlockParameterBaseAddr in paramlib.tlc.

LibBlockParameterDataTypeId

LibBlockParameterDataTypeId(param) returns the numeric ID corresponding to the data type of the specified block parameter.

See LibBlockParameterDataTypeId in paramlib.tlc.

LibBlockParameterDataTypeName

LibBlockParameterDataTypeName(param, reim) returns the name of the data type corresponding to the specified block parameter.

See LibBlockParameterDataTypeName in paramlib.tlc.

LibBlockParameterDimensions

LibBlockParameterDimensions(param) returns a row vector of length N (where N >= 1) giving the dimensions of the parameter data.

For example,

%assign dims  = LibBlockParameterDimensions("paramName")
%assign nDims = SIZE(dims,1)
%foreach i=nDims
   /* Dimension %<i+1> = %<dims[i]> */
%endforeach

LibBlockParameterDimensions differs from LibBlockParameterSize in that it returns the dimensions of the parameter data prior to collapsing the Matrix parameter to a column-major vector. The collapsing occurs for run-time parameters that have specified their outputAsMatrix field as False.

See LibBlockParameterDimensions in paramlib.tlc.

LibBlockParameterIsComplex

LibBlockParameterIsComplex(param) returns 1 if the specified block parameter is complex, 0 otherwise.

See LibBlockParameterIsComplex in paramlib.tlc.

LibBlockParameterSize

LibBlockParameterSize(param) returns a vector of size 2 in the format [nRows, nCols] where nRows is the number of rows and nCols is the number of columns.

See LibBlockParameterSize in paramlib.tlc.

LibBlockParameterString

Based on the block parameter reference (param), LibBlockParameterString(param) returns the specified block parameter interpreted as a string, for example, this function returns:

  • STRINGOF(param.Value[0]) if the parameter is a row matrix

  • STRINGOF(param.Value) otherwise

Note

It is an error to invoke this function with a matrix-valued parameter with more than one row.

If you are accessing only a parameter value by using LibBlockParameterValue or LibBlockParameterString, consider converting the parameter from Tunable to Nontunable. Then, use ssWriteRTWParamSettings to write the value of the parameter to the model.rtw file. Inlining parameters reduces RAM usage because the code generator uses the numeric values of parameters, instead of their symbolic names, in the generated code.

See LibBlockParameterString in paramlib.tlc.

LibBlockParameterValue

Based on the block parameter reference (param) and the index element of the array (elidx), LibBlockParameterValue(param, elIdx) returns the numeric value of a parameter. You can use the LibBlockParameterWidth(param) function to get the width of the array, and then use elidx (valid values of 0 to width-1) to get a particular element of the array.

If you are accessing only a parameter value by using LibBlockParameterValue or LibBlockParameterString, consider converting the parameter from Tunable to Nontunable. Then, use ssWriteRTWParamSettings to write the value of the parameter to the model.rtw file. Inlining parameters reduces RAM usage because the code generator uses the numeric values of parameters, instead of their symbolic names, in the generated code.

Example

If you want to generate code for a different integrator depending on a parameter for a block, use:

%assign mode = LibBlockParameterValue(Integrator, 0)
%switch (mode)
   %case 1
      %<CodeForIntegrator1>
      %break
   %case 2
      %<CodeForIntegrator2>
      %break
   %default
      Error: Unrecognized integrator value.
      %break
%endswitch

See LibBlockParameterValue in paramlib.tlc.

LibBlockParameterWidth

LibBlockParameterWidth(param) returns the number of elements (width) of a parameter.

See LibBlockParameterWidth in paramlib.tlc.

LibGetParameterValue

LibGetParameterValue returns the data vector of the model parameter written to the ModelParameters record in the model.rtw. For example, you can use:

%assign numRowValues = SIZE(LibGetParameterValue(RowIndex), 1)
For records that are not model parameters, the code generator returns the record.Value. Use the LibGetParameterValue function to access the data vector of the model parameter instead of fetching the record.Value.

If the data vector of the model parameter that the function LibGetParameterValue returns is a numeric scalar and results in an error for a numeric expression, append a [0] to it. For example, if

%assign sum = LibGetParameterValue(RowIndex) + 10
returns this error:
“The + operator only works on numeric arguments”
Then modify the expression as:
%assign sum = LibGetParameterValue(RowIndex)[0] + 10

See LibGetParameterValue in paramlib.tlc.

Related Topics