This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.


Convert number to nearest value representable by specified fixed-point data type


outValue = num2fixpt(OrigValue, FixPtDataType, FixPtScaling,
    RndMeth, DoSatur)


num2fixpt(OrigValue, FixPtDataType, FixPtScaling, RndMeth, DoSatur) returns the result of converting OrigValue to the nearest value representable by the fixed-point data type FixPtDataType. Both OrigValue and outValue are of data type double. As illustrated in the example that follows, you can use num2fixpt to investigate quantization error that might result from converting a number to a fixed-point data type. The arguments of num2fixpt include:


Value to be converted to a fixed-point representation. Must be specified using a double data type.


The fixed-point data type used to convert OrigValue.


Scaling of the output in either Slope or [Slope Bias] format. If FixPtDataType does not specify a generalized fixed-point data type using the sfix or ufix command, FixPtScaling is ignored.


Rounding technique used if the fixed-point data type lacks the precision to represent OrigValue. If FixPtDataType specifies a floating-point data type using the float command, RndMeth is ignored. Valid values are Zero, Nearest, Ceiling, or Floor (the default).


Indicates whether the output should be saturated to the minimum or maximum representable value upon underflow or overflow. If FixPtDataType specifies a floating-point data type using the float command, DoSatur is ignored. Valid values are on or off (the default).


Suppose you wish to investigate the quantization effect associated with representing the real-world value 9.875 as a signed, 8-bit fixed-point number. The command

num2fixpt(9.875, sfix(8), 2^-1)

ans =


reveals that a slope of 2^-1 results in a quantization error of 0.375. The command

num2fixpt(9.875, sfix(8), 2^-2)

ans =


demonstrates that a slope of 2^-2 reduces the quantization error to 0.125. But a slope of 2^-3, as used in the command

num2fixpt(9.875, sfix(8), 2^-3)

ans =


eliminates the quantization error entirely.

Introduced before R2006a

Was this topic helpful?