Parameter Functions

LibBlockMatrixParameter
(param, rucv, rlcv, ridx, cucv, clcv, cidx)

Returns the appropriate 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.

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 matlabroot/rtw/c/tlc/lib/paramlib.tlc.

LibBlockMatrixParameterAddr
(param, rucv, rlcv, ridx, cucv, clcv, cidx)

Returns the address of a matrix parameter.

See LibBlockMatrixParameterAddr in matlabroot/rtw/c/tlc/lib/paramlib.tlc.

LibBlockMatrixParameterBaseAddr(param)

Returns the base address of a matrix parameter.

See LibBlockMatrixParameterBaseAddr in matlabroot/rtw/c/tlc/lib/paramlib.tlc.

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 matlabroot/rtw/c/tlc/lib/paramlib.tlc.

LibBlockParameter(param, ucv, lcv, sigIdx)

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 returns the appropriate reference to a block parameter. The returned value is always 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.

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 Real-Time Workshop 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 matlabroot/rtw/c/tlc/lib/paramlib.tlc.

LibBlockParameterAddr(param, ucv, lcv, idx)

Returns the address of a block parameter.

Using LibBlockParameterAddr to access a parameter when the global InlineParameters 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 Inline parameters is set and the expression has multiple tunable/rolled variables in it will result in an error.

See LibBlockParameterAddr in matlabroot/rtw/c/tlc/lib/paramlib.tlc.

LibBlockParameterBaseAddr(param)

Returns the base address of a block parameter.

Using LibBlockParameterBaseAddr to access a parameter when the global InlineParameters 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 Inline parameters is set and the expression has multiple tunable/rolled variables in it will result in an error.

See LibBlockParameterBaseAddr in matlabroot/rtw/c/tlc/lib/paramlib.tlc.

LibBlockParameterDataTypeId(param)

Returns the numeric ID corresponding to the data type of the specified block parameter.

See LibBlockParameterDataTypeId in matlabroot/rtw/c/tlc/lib/paramlib.tlc.

LibBlockParameterDataTypeName(param, reim)

Returns the name of the data type corresponding to the specified block parameter.

See LibBlockParameterDataTypeName in matlabroot/rtw/c/tlc/lib/paramlib.tlc.

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 matlabroot/rtw/c/tlc/lib/paramlib.tlc.

LibBlockParameterIsComplex(param)

Returns 1 if the specified block parameter is complex, 0 otherwise.

See LibBlockParameterIsComplex in matlabroot/rtw/c/tlc/lib/paramlib.tlc.

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 matlabroot/rtw/c/tlc/lib/paramlib.tlc.

LibBlockParameterString(param)

Returns the specified block parameter interpreted as a string, for example, this function returns:

If you are only accessing the parameter values using LibBlockParameterString or LibBlockParameterValue, you should consider converting the parameter to a ParamSetting. This produces more efficient code since the parameter is not declared as a variable in the code.

See LibBlockParameterString in matlabroot/rtw/c/tlc/lib/paramlib.tlc.

LibBlockParameterValue(param, elIdx)

Determine the numeric value of a parameter. If you are only accessing the parameter values using LibBlockParameterValue or LibBlockParameterString, you should consider converting the parameter to a ParamSetting. This produces more efficient code since the parameter is not declared as a variable in the code.

Example

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

%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 matlabroot/rtw/c/tlc/lib/paramlib.tlc.

LibBlockParameterWidth(param)

Returns the number of elements (width) of a parameter.

See LibBlockParameterWidth in matlabroot/rtw/c/tlc/lib/paramlib.tlc.

  


 © 1984-2008- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS