Main Content

addFunctionReplacement

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');

Create a code generation configuration object to generate a standalone C static library.

cfg = coder.config('lib');

Convert the floating-point MATLAB function, myfunc, to fixed-point, and generate C code.

codegen -float2fixed fixptcfg -config cfg myfunc

When you generate code, the code generator replaces instances of myadd with fi_myadd during floating-point to fixed-point conversion.