Main Content

Cast and Quantize Data

Quantization to fixed-point and floating-point data types, casting between data types

When designing fixed-point algorithms, use cast, zeros, ones, eye, and subsasgn to separate the core algorithm from data type definitions. These functions allow you to use double-precision, single-precision, and fixed-point data types in the same code. Manual Fixed-Point Conversion Best Practices describes how to get from generic MATLAB® code to an efficient fixed-point implementation.

To simulate full-precision arithmetic using doubles and quantize only at the output of the algorithm, use quantizenumeric.

To simulate floating-point data with arbitrary word length and exponent length, use the quantizer object and associated object functions.


expand all

eyeCreate identity matrix with fixed-point properties
onesCreate array of all ones with fixed-point properties
zerosCreate array of all zeros with fixed-point properties
castCast variable to different data type
cast64BitFiToIntCast fi object types that can be exactly represented to a 64-bit integer data type
cast64BitIntToFiCast 64-bit integer types to an equivalent fi object type
castFiToIntCast fi object to equivalent integer data type
castFiToMATLABCast fi object type to an equivalent built-in MATLAB data type
castIntToFiCast an integer data type to equivalent fi type
subsasgnSubscripted assignment
subsrefSubscripted reference
quantizenumericQuantize numeric data
quantizerCreate quantizer object
quantizeQuantize numeric data using quantizer object
assignmentquantizerCreate quantizer object with fi object attributes
copyobjMake independent copy of quantizer object
randquantGenerate uniformly distributed, quantized random number using quantizer object
resetReset objects to initial conditions
unitquantizeQuantize numeric data using quantizer object except numbers within eps of +1
unitquantizerCreate unitquantizer object
denormalmaxLargest denormalized quantized number for quantizer object
denormalminSmallest denormalized quantized number for quantizer object
epsQuantized relative accuracy for fi or quantizer objects
exponentbiasExponent bias for quantizer object
exponentlengthExponent length of quantizer object
exponentmaxMaximum exponent for quantizer object
exponentminMinimum exponent for quantizer object
fractionlengthFraction length of quantizer object
getProperty values of object
lsbScaling of least significant bit of fi object, or value of least significant bit of quantizer object
rangeNumerical range of fi or quantizer object
realmaxLargest positive fixed-point value or quantized number
realminSmallest positive normalized fixed-point value or quantized number
setSet or display property values for quantizer objects
tostringConvert fi, fimath, numerictype, or quantizer object to string
wordlengthWord length of quantizer object
logreportQuantization report
maxlogLog maximums
minlogLog minimums
noperationsNumber of quantization operations by quantizer object
noverflowsNumber of overflows
nunderflowsNumber of underflows
resetlogClear log for fi or quantizer object
bin2numConvert two's complement binary string to number using quantizer object
hex2numConvert hexadecimal string to number using quantizer object
num2binConvert number to binary representation using quantizer object
num2hexConvert number to hexadecimal equivalent using quantizer object
num2intConvert number to signed integer using quantizer object
isequalDetermine whether real-world values of two fi objects are equal, or determine whether properties of two fimath, numerictype, or quantizer objects are equal
isfixedDetermine whether input is fixed-point data type
isfloatDetermine whether input is floating-point data type
isquantizerDetermine whether input is quantizer object
errmeanMean of quantization error
errpdfProbability density function of quantization error
errvarVariance of quantization error
roundRound fi object toward nearest integer or round input data using quantizer object
fixed.QuantizerQuantize fixed-point numbers
quantizeQuantize fi values using fixed.Quantizer object