Single-precision variables in MATLAB® are stored as 4-byte (32-bit) floating-point values of data type (class)
single. For example:
y = single(10); whos y
Name Size Bytes Class Attributes y 1x1 4 single
For more information on floating-point values, see Floating-Point Numbers.
If you have an array of a different type, such as
int8, then you can convert that array to a single precision array by
X — Input array
scalar | vector | matrix | multidimensional array
Input array, specified as a scalar, vector, matrix, or multidimensional array.
Convert to Single-Precision Variable
Convert a double-precision variable to single precision with the
x = 100; xtype = class(x)
xtype = 'double'
y = single(x)
y = single 100
Calculate with arrays that have more rows than fit in memory.
This function fully supports tall arrays. For more information, see Tall Arrays.
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Usage notes and limitations:
When using single-precision integers with the
colonoperator, if either of the end points have a value that is greater in absolute value than
flintmax('single')in your MATLAB code, then the generated code might produce different values as compared to the MATLAB code. For example:
function z = mismatch_values a = single(1); b = flintmax('single') + 2; d = single(9); z = a:d:b; end
zvalues that are calculated by the generated code and MATLAB code are different due to the different rounding methods used by the generated code and MATLAB code.
GPU Code Generation
Generate CUDA® code for NVIDIA® GPUs using GPU Coder™.
Accelerate code by running on a graphics processing unit (GPU) using Parallel Computing Toolbox™.
This function fully supports GPU arrays. For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).
Partition large arrays across the combined memory of your cluster using Parallel Computing Toolbox™.
This function fully supports distributed arrays. For more information, see Run MATLAB Functions with Distributed Arrays (Parallel Computing Toolbox).