Main Content

coder.SingleConfig Class

Namespace: coder

Double-precision to single-precision conversion configuration object

Description

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.

Creation

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

Properties

expand all

Suffix that the single-conversion process uses for generated single-precision filenames, specified as a character vector.

Option to enable simulation data logging for comparison plotting, specified as true or false. Comparion plotting plots the differences introduced by single-precision conversion.

Name of function to use for comparison plots, specified as a character vector

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.

Option to use Simulation Data Inspector for comparison plots, specified as true or false.

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

Names of test files, 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.

Option to enable numerics testing to verify the generated single-precision code, specified as true or false. The test file runs the single-precision code.

Methods

expand all

Examples

collapse all

Create a coder.SingleConfig object.

scfg = coder.config('single'); 

Set the properties of the double-precision to single-precision conversion 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 

Alternatives

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