Main Content

quantize

Quantize interval to range of numeric data type

Description

quantizedinterval = quantize(interval, numerictype) returns the quantized range of fixed.Interval object, interval, quantized to the numeric type specified by numerictype.

example

quantizedinterval = quantize(interval, numerictype, Name,Value) returns the quantized range of fixed.Interval object, interval, with additional properties specified as name-value pairs.

example

Examples

collapse all

Create a fixed.Interval object and find the range of the Interval object quantized to an unsigned 8-bit integer.

interval = fixed.Interval(-200,200);
quantizedInterval = quantize(interval, 'fixdt(0,8,0)')
quantizedInterval =

  1×2 uint8 row vector

     0   200

Because fixdt(0,8,0) is equivalent to uint8, the quantize function returns the quantized range as a uint8 row vector with the endpoints within the representable range of the numeric type.

To return the quantized row vector as a fixed-point data type, set the 'PreferBuiltIn' property to false.

quantizedInterval = quantize(interval, 'fixdt(0,8,0)',...
 'PreferBuiltIn', false)
quantizedInterval = 

     0   200

          DataTypeMode: Fixed-point: binary point scaling
            Signedness: Unsigned
            WordLength: 8
        FractionLength: 0

Input Arguments

collapse all

Input fixed.Interval object, specified as a fixed.Interval object, or an array of fixed.Interval objects.

Numeric data type to quantize the Interval, specified as a Simulink.Numerictype object, an embedded.numerictype object, or a character vector representing a numeric data type, for example, 'single'.

Example: quantizedinterval = quantize(interval, 'fixdt(1,16,8)');

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: interval = quantize(interval, 'fixdt(1,16,0)', 'PreferBuiltIn', false, 'PreferStrict', true);

When this property is true, if the specified numerictype has an equivalent built-in integer type the software returns the built-in type. For example, when this property is true, a specified numerictype of 'fixdt(1,8,0)' would return an int8.

Data Types: logical

When this property is true, all ends are quantized to the closest representable values within original intervals regardless of whether the intervals are closed or open.

Data Types: logical

Output Arguments

collapse all

N-by-2 matrix with rows consisting of endpoints of input Interval objects quantized to the numeric data type specified by numerictype.

When the 'PreferStrict' property is set to false, the end points after quantization may lie outside the original interval.

Version History

Introduced in R2019b