主要内容

Limitations for Block Parameter Tunability in Generated Code

块参数,matlab®变量,或金宝appsimulink.parameter如果对象在生成的代码中显示为存储在内存中的数据,例如全局变量。例如,应用存储课时出口global对于参数对象,参数对象在生成的代码中显示可调。当您设置时默认参数行为to可调,MATLAB变量和参数对象在生成的代码中显示可调。根据定义,模型参数也看起来很可调。

我的理解是在某些情况下,代码生成器t maintain tunability of a parameter, variable, object, or expression. In this case, the code generator inlines the numeric value, preventing you from changing the value during code execution.

To detect these conditions in your model, set the model configuration parameter检测可调性丧失(看检测可调性丧失) 至warning或者错误

可调表达限制

您可以将块参数值指定为使用的表达式金宝appsimulink.parameter对象或工作区变量。例如,您可以使用表达式5 * gainparam。For general information about using expressions to set block parameter values, seeUse Mathematical Expressions, MATLAB Functions, and Custom Functions。For limitations with respect to expressions that you use to set the values of金宝appsimulink.parameter对象,请参阅具有表达值的参数对象的代码生成

A可调工作区变量is a金宝appsimulink.parameterobject or workspace variable that appears tunable in the generated code. For example, an object or variable is tunable if you apply a storage class other than汽车或者如果您设置默认参数行为to可调

包含一个或多个可调工作空间变量,模型参数或可调掩码参数的表达式称为tunable expression。表达式是可调的,因为代码生成器试图保留代码中的表达式。由于代码生成器保留了表达式,因此您可以在代码执行过程中更改参数数据的值。

The code generator reduces certain expressions to an inlined numeric value in the generated code. The inlining renders workspace variables in the expression nontunable. To avoid loss of tunability due to unsupported expressions, observe these guidelines:

  • 涉及复杂的表达(i) workspace variables or parameter objects are not supported.

  • Certain operators and functions cause the code generator to reduce expressions and remove tunability. To determine whether an operator or function causes loss of tunability, use the information in this table.

    类别 操作员或功能

    1

    + - 。* ./ <> <=> ==〜=&|

    2

    * /

    3

    abs,ACOS,asin,晒黑,atan2,布尔,Ceil,cos,Cosh,exp,地面,日志,日志10,符号,sin,sinh,SQRT,棕褐色,棕褐色h,single,int8,INT16,INT32,uint8,UINT16,uint32

    4

    :。 ^ ^ [] {}。\。\'。',;

    • 使用1类操作员而不会损失可调性。

    • Use operators from category 2 in expressions as long as at least one operand is a scalar. For example, scalar/scalar and scalar/matrix operand combinations are supported, but matrix/matrix combinations are not supported.

    • You can use tunable workspace variables as arguments for the functions in category 3. If you use other functions, the code generator removes the tunability of the arguments.

    • The operators in category 4 are not supported.

  • TheFCN如果块不支持代码生成或引用模型中金宝app的可调表达式。

  • You can write mask initialization code that creates and modifies variables. If you use those variables in an expression, the expression is not tunable.

  • You can specify a data type for the金宝appsimulink.parameterobjects or workspace variables that make up expressions. As long as the data type of these variables and objects and the data type of the corresponding block parameters are the same or双倍的, the code generator can preserve tunability.

如果the code generator preserves tunability of a parameter expression that includes at least one element of an integer type, simulation and execution of generated code can produce results that are numerically inconsistent. Evaluation of the expression in the generated code results in an overflow while the expression saturates during simulation. For more information, see模型和生成代码仿真结果的数值一致性

线性块参数可调性

这些块有一个实现parameter that affects the tunability of their numeric parameters:

  • Transfer Fcn

  • 州空间

  • 离散状态空间

设置实现参数,您必须使用命令提示符:

set_param(gcb,'实现','auto')

For the实现参数,您可以选择以下选项:

  • 一般的: The block's numeric parameters appear tunable in the generated code.

  • sparse: The generated code represents the block’s parameters as transformed values that increase efficiency. The parameters are not tunable.

  • 汽车:默认值。如果一个或多个块的参数是可调的(例如,因为您使用可调参数对象来设置参数值),则该块使用一般的realization. Otherwise, the block uses thesparserealization.

    To tune the parameter values of one of these blocks during an external mode simulation, the block must use the一般的realization.

参数结构

As described in将数据组织成生成的代码中的结构,您可以在生成的代码中创建参数数据的结构。

  • 如果a parameter structure is tunable, the numeric fields of the structure are tunable in the generated code. However, if a field contains a nontunable entity, such as a multidimensional array, the structure fields are not tunable.

  • 您不能将参数结构中的单个子结构或字段声明为可调。你不能使用金宝appsimulink.parameterobject as the value of a structure field. Instead, you must store the entire structure in the parameter object.

相关话题