Main Content

addSpecification

Class: fxpOptimizationOptions

Specify known data types in a system

Description

example

addSpecification(options,Name,Value) specifies known data types in the model using name-value pairs. 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.

Input Arguments

expand all

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

Example: opt = fxpOptimizationOptions;

Name-Value Arguments

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.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

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

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.

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.

Load the system for which you want to optimize the data types.

load_system('ex_auto_gain_controller');

To specify that 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 data type.

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

The fxpOptimizationOptions object, opt, specifies options to use during data type optimization. To specify the data type of the input to the system, use the addSpecification method.

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

You can view all specifications added to a fxpOptimizationOptions object using the showSpecifications method.

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

      1      OutDataTypeStr    ex_auto_gain_controller/input_signal    'int8'

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

Create a Simulink.Parameter object to set the value a parameter in your model.

myParam = Simulink.Parameter(2);
myParamCopy = copy(myParam);

Make a copy of the parameter and set the data type to the desired known value.

myParamCopy = copy(myParam);
myParamCopy.DataType = 'single';

Specify the variable using a Simulink.Simulation.Variable object.

var = Simulink.Simulation.Variable('myParam',myParamCopy);

The fxpOptimizationOptions object, opt, specifies options to use during data type optimization. To specify the data type of the variable, use the addSpecification method.

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

You can view all specifications added to a fxpOptimizationOptions object using the showSpecifications method.

showSpecifications(opt)

Version History

Introduced in R2020a

expand all