Contenido principal

addSpecification

R2026b

Class: fxpOptimizationOptions

Specify known data types in a system

Description

addSpecification(options,Name=Value) specifies known data types in the model using one or more name-value arguments. After specifying these known parameters, if you optimize the data types in a system, the optimization process will not change the specified block parameter data type. Specifications are applied to the model during evaluation and to the final model. Specifications are not considered during range collection.

You can use this method in cases where parts of a system are known to always be a certain data type. For example, if the input to your system comes from an 8-bit sensor.

example

Input Arguments

expand all

Associated fxpOptimizationOptions object in which to specify a known data type for a system.

Example: opt = fxpOptimizationOptions;

Name-Value Arguments

expand all

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Example: addSpecification(opt,BlockParameter=bp,Variable=var)

Block parameters, specified as an element or array of Simulink.Simulation.BlockParameter objects specifying the data types of block parameters that should not change during the optimization. The value specified must be a valid data type for the block.

Variable values, specified as an element or array of Simulink.Simulation.Variable objects specifying the data types of variables that should not change during the optimization. You can specify values for Simulink.Parameter or Simulink.NumericType variables.

Examples

expand all

This example shows how to specify known data types for block parameters within your system.

Suppose you want to optimize data types for the system under design in the ex_auto_gain_controller model, as described in the Optimize Fixed-Point Data Types example. The input to the system you are converting will always be an eight-bit integer.

Create a BlockParameter object that specifies the block parameter and the known eight-bit integer data type.

bp = Simulink.Simulation.BlockParameter(...
'ex_auto_gain_controller/input_signal',OutDataTypeStr='int8');

Use the addSpecification function to specify the data type of the input to the system under design in the fxpOptimizationOptions object.

opt = fxpOptimizationOptions;
addSpecification(opt,BlockParameter=bp);

Optionally, use the showSpecifications function to display all specifications added to the fxpOptimizationOptions object.

showSpecifications(opt)
    Index         Name                      BlockPath                  Value 
    _____    ______________    ____________________________________    ______

      1      OutDataTypeStr    ex_auto_gain_controller/input_signal    'int8'

    varSpecs
    ________

This example shows how to specify known data types for variables within your system.

Suppose you use a Simulink.Parameter object to set the value of a parameter in your model. Make a copy of this parameter and set the data type to the desired known value. Specify the variable using a Simulink.Simulation.Variable object.

myParam = Simulink.Parameter(2);
myParamCopy = copy(myParam);
myParamCopy.DataType = 'single';
var = Simulink.Simulation.Variable('myParam',myParamCopy);

Use the addSpecification function to add this specification to the fxpOptimizationOptions object.

opt = fxpOptimizationOptions();
addSpecification(opt,Variable=var);

Tips

Use the showSpecifications function to view all specifications added to an fxpOptimizationOptions object.

Version History

Introduced in R2020a

expand all