This is machine translation

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

Create Numeric Arrays

This example shows how to create a numeric variable. In the MATLAB® computing environment, all variables are arrays, and by default, numeric variables are of type double (that is, double-precision values). For example, create a scalar value.

A = 100;

Because scalar values are single element, 1-by-1 arrays,

whos A


Name      Size            Bytes  Class     Attributes

A         1x1                 8  double              

To create a matrix (a two-dimensional, rectangular array of numbers), you can use the [] operator.

B = [12, 62, 93, -8, 22; 16, 2, 87, 43, 91; -4, 17, -72, 95, 6]

When using this operator, separate columns with a comma or space, and separate rows with a semicolon. All rows must have the same number of elements. In this example, B is a 3-by-5 matrix (that is, B has three rows and five columns).

B =
    12    62    93    -8    22
    16     2    87    43    91
    -4    17   -72    95     6

A matrix with only one row or column (that is, a 1-by-n or n-by-1 array) is a vector, such as

C = [1, 2, 3]


D = [10; 20; 30]

For more information, see:

Was this topic helpful?