Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

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;
whos x
  Name      Size            Bytes  Class     Attributes

  x         1x1                 8  double  

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

Creation

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

If you have an array of a different type, such as single or int8, then you can convert that array to double precison using the double function.

Syntax

Y = double(X)

Description

example

Y = double(X) converts the values in X to 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 type double. You can use the class function to verify a variable's type.

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

Use the double function to convert variables that are not double precision to type double.

y = true
y = logical
   1

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

Tips

  • When you are creating a class, overload double when 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