Main Content


Convert double-precision MATLAB code to single-precision MATLAB code



convertTosingle options fcn_1, ..., fcn_n generates single-precision MATLAB® code from the specified function or functions. When you use this syntax, you must provide a test file that convertToSingle can use to determine the properties of the input parameters. To specify the test file, use coder.config('single') to create a coder.SingleConfig object. Specify the TestBenchName property.


convertTosingle options fcn_1, -args args_1 ,..., fcn_n -args args_n specifies the properties of the input arguments.


collapse all

Generate single-precision code from a double-precision function myfun.m. Specify a test file for determining the argument properties and for verification of the converted types. Plot the error between the double-precision and single-precision values.

scfg = coder.config('single');
scfg.TestBenchName = 'myfun_test';
scfg.TestNumerics = true;
scfg.LogIOForComparisonPlotting = true;
convertToSingle -config scfg myfun 

Convert myfun1.m and myfun2.m to single precision. Specify that myfun1 has a double scalar argument and myfun2 has a 2x3 double argument.

convertToSingle -config scfg myfun1 -args {0} myfun2 -args {zeros(2, 3)} 

Generate single-precision code from a double-precision function, myfun.m, whose first argument is double scalar and whose second argument is 2x3 double.

 convertToSingle  myfun -args {0, zeros(2, 3)}

Input Arguments

collapse all

MATLAB function from which to generate single-precision code.

Definition of the size, class, and complexity of the input arguments specified as a cell array of types or example values. To create a type, use coder.typeof.

Specify one of the following single-conversion options.

-config config_object

Specify the configuration object to use for conversion of double-precision MATLAB code to single-precision MATLAB code. To create the configuration object, use


If you do not use this option, the conversion uses a default configuration. When you omit -config, to specify the properties of the input arguments, use -args.

-globals global_values

Specify names and initial values for global variables in MATLAB files.

global_values is a cell array of global variable names and initial values. The format of global_values is:

{g1, init1, g2, init2, ..., gn, initn}

gn is the name of a global variable. initn is the initial value. For example:

-globals {'g', 5}

Alternatively, use this format:

-globals {global_var, {type, initial_value}}

type is a type object. To create the type object, use coder.typeof.

If you do not provide initial values for global variables using the -globals option, convertToSingle checks for the variable in the MATLAB global workspace. If you do not supply an initial value, convertToSingle generates an error.

Version History

Introduced in R2015b