Main Content

addFunctionReplacement

Class: coder.FixPtConfig
Namespace: coder

Replace floating-point function with fixed-point function during fixed-point conversion

Syntax

addFunctionReplacement(floatFn,fixedFn)

Description

addFunctionReplacement(floatFn,fixedFn) specifies a function replacement in a coder.FixPtConfig object. During floating-point to fixed-point conversion, the conversion process replaces the specified floating-point function with the specified fixed-point function. The fixed-point function must be in the same folder as the floating-point function or on the MATLAB® path.

Input Arguments

expand all

Name of floating-point function, specified as a string.

Name of fixed-point function, specified as a string.

Examples

expand all

Suppose that:

  • The function myfunc calls a local function myadd.

  • The test function mytest calls myfunc.

  • You want to replace calls to myadd with the fixed-point function fi_myadd.

Create a coder.FixPtConfig object, fixptcfg, with default settings.

fixptcfg = coder.config('fixpt');

Set the test bench name. In this example, the test bench function name is mytest.

fixptcfg.TestBenchName = 'mytest';

Specify that the floating-point function, myadd, should be replaced with the fixed-point function, fi_myadd.

fixptcfg.addFunctionReplacement('myadd', 'fi_myadd');

Convert the floating-point MATLAB function, myfunc, to fixed-point.

fiaccel -float2fixed fixptcfg myfunc

fiaccel replaces myadd with fi_myadd during floating-point to fixed-point conversion.