Documentation

double

Double-precision arrays

Description

By default, MATLAB®stores all numeric variables as double-precision floating-point values that are 8 bytes (64 bits). These variables have data type (class)double. For example:

x = 10; whosx
Name Size Bytes Class Attributes x 1x1 8 double

For more information on floating-point values, seeFloating-Point Numbers.

Creation

You can create a double-precision array using the[]operator, such asA = [1 2 3; 4 5 6]. In addition, many functions return double-precision arrays, such assin.

If you have an array of a different type, such assingleorint8, then you can convert that array to double precison using thedoublefunction.

Syntax

Y = double(X)

Description

example

Y = double(X)converts the values inXto double precision.

Input Arguments

expand all

Input array, specified as a scalar, vector, matrix, or multidimensional array.

Data Types:single|int8|int16|int32|int64|uint8|uint16|uint32|uint64|logical|char|string

Examples

expand all

By default, numbers in MATLAB are of the data typedouble. You can use theclassfunction to verify a variable's type.

x = 100;xtype类(x) =
xtype = 'double'

Use thedoublefunction to convert variables that are not double precision to typedouble.

y = true
y =logical1
ydouble = double(y); ynewtype = class(ydouble)
ynewtype = 'double'

Tips

  • When you are creating a class, overloaddoublewhen it makes sense to convert an object of that class to a double-precision value.

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Introduced before R2006a

Was this topic helpful?