This is machine translation

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

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.


Class: coder.SingleConfig
Package: coder

Replace double-precision function with single-precision function during single-precision conversion




addFunctionReplacement(doubleFn,singleFn) specifies a function replacement in a coder.SingleConfig object. During double-precision to single-precision conversion, the conversion process replaces the specified double-precision function with the specified single-precision function. The single-precision function must be in the same folder as the double-precision function or on the MATLAB® path. It is a best practice to provide unique names to local functions that a replacement function calls. If a replacement function calls a local function, do not give that local function the same name as a local function in a different replacement function file.

Input Arguments

expand all

Name of double-precision function, specified as a string.

Name of single-precision function, specified as a string.


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 single-precision function single_myadd.

Create a coder.SingleConfig object, scfg, with default settings.

scfg = coder.config('single');

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

scfg.TestBenchName = 'mytest';

Specify that you want to replace the double-precision function, myadd, with the single-precision function, single_myadd.

scfg.addFunctionReplacement('myadd', 'single_myadd');

Convert the double-precision MATLAB function, myfunc to a single-precision MATLAB function.

convertToSingle -config scfg myfunc

The double-precision to single-precision conversion replaces instances of myadd with single_myadd.

Introduced in R2015b