Main Content

coder.SingleConfig class

Package: coder

Double-precision to single-precision conversion configuration object


A coder.SingleConfig object contains the configuration parameters that the MATLAB® Coder™ codegen function requires to convert double-precision code to single-precision MATLAB code. To pass this object to the codegen function, use the -double2single option.


scfg = coder.config('single') creates a coder.SingleConfig object for double-precision to single-precision conversion.


expand all

Suffix that the single-conversion process uses for generated single-precision files.

Enable simulation data logging to plot the data differences introduced by single-precision conversion.

Name of function to use for comparison plots.

To enable comparison plotting, set LogIOForComparisonPlotting to true. This option takes precedence over PlotWithSimulationDataInspector.

The plot function must accept three inputs:

  • A structure that holds the name of the variable and the function that uses it.

  • A cell array to hold the logged floating-point values for the variable.

  • A cell array to hold the logged values for the variable after fixed-point conversion.

Use Simulation Data Inspector for comparison plots.

LogIOForComparisonPlotting must be set to true to enable comparison plotting. The PlotFunction option takes precedence over PlotWithSimulationDataInspector.

Test file name or names, specified as a character vector or cell array of character vectors. Specify at least one test file.

If you do not explicitly specify input parameter data types, the conversion uses the first file to infer these data types.

Enable numerics testing to verify the generated single-precision code. The test file runs the single-precision code.


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


collapse all

Create a coder.SingleConfig object.

scfg= coder.config('single'); 

Set the properties of the doubles-to-singles configuration object. Specify the test file. In this example, the name of the test file is myfunction_test. The conversion process uses the test file to infer input data types and collect simulation range data. Enable numerics testing and generation of comparison plots.

scfg.TestBenchName = 'myfunction_test';
scfg.TestNumerics = true;
scfg.LogIOForComparisonPlotting = true;

Run codegen. Use the -double2single option to specify the coder.SingleConfig that you want to use. In this example, the MATLAB function name is myfunction.

codegen -double2single scfg myfunction 


You can convert double-precision MATLAB code to single-precision C/C++ code by using the 'singleC' option of the codegen function.

You can convert double-precision MATLAB code to single-precision code using the MATLAB Coder app. Open the app using one of these methods:

  • On the Apps tab, in the Code Generation section, click MATLAB Coder.

  • Use the coder command.

Version History

Introduced in R2015b