Programming and Data Types |

There are 15 fundamental data types (or classes) in MATLAB. Each of these data types is in the form of an array. This array is a minimum of 0-by-0 in size and can grow to an n-dimensional array of any size. Two-dimensional versions of these arrays are called *matrices.*

All of the fundamental data types are shown in lowercase text in the diagram below. Additional data types are user-defined, object-oriented

(a subclass of *user classes*`structure`

), and

, that you can use with the MATLAB interface to Java.*java classes*

Matrices of type `double`

and `logical`

may be either `full`

or `sparse`

. For matrices having a small number of nonzero elements, a sparse matrix requires a fraction of the storage space required for an equivalent full matrix. Sparse matrices invoke special methods especially tailored to solve sparse problems.

The `logical`

data type represents a logical `true`

or `false`

value using the numbers `1`

and `0`

, respectively. MATLAB returns logical values from its relational (e.g., `>`

, `~=`

) and logical (e.g., `&&`

, `xor`

) operations and functions.

The `char`

data type holds characters. A character string is merely a 1-by-n array of characters. You can use `char`

to hold an m-by-n array of strings as long as each string in the array has the same length. (This is because MATLAB arrays must be rectangular.) To hold an array of strings of unequal length, use a `cell`

array.

Numeric data types include signed and unsigned integers, and single- and double- precision floating point numbers. The following hold true for numeric data types in MATLAB:

- All data types support basic array operations, such as subscripting and reshaping.
- All MATLAB computations are done in double-precision.
- To perform mathematical operations on integer or single precision arrays, you must convert them to double precision using the
`double`

function. - Integer and single precision arrays offer more memory efficient storage than double-precision.

A `cell array`

provides a storage mechanism for dissimilar kinds of data. You can store arrays of different types and/or sizes within the cells of a `cell`

array. For example, you can store a 1-by-50 `char`

array, a 7-by-13 `double`

array, and a 1-by-1 `uint32`

in cells of the same `cell`

array. You access data in a `cell`

array using the same matrix indexing used on other MATLAB matrices and arrays.

The MATLAB `structure`

data type is similar to the `cell`

array in that it also stores dissimilar kinds of data. But, in this case, it stores the data in named fields rather than in cells. This enables you to attach a name to the groups of data stored within the structure. You access data in a structure using these same field names.

A `function handle`

holds information to be used in referencing a function. When you create a function handle, MATLAB captures all the information about the function that it needs to locate and execute, or *evaluate*, it later on. Typically, a function handle is passed in an argument list to other functions. It is then used in conjunction with `feval`

to evaluate the function to which the handle belongs.

MATLAB data types are implemented as classes. You can also create MATLAB classes of your own. These user-defined classes inherit from the MATLAB `structure`

class and are shown in the previous diagram as a subset of `structure`

.

MATLAB provides an interface to the Java programming language that enables you to create objects from Java classes and call Java methods on these objects. A Java class is a MATLAB data type. There are built-in and third-party classes that are already available through the MATLAB interface. You can also create your own Java class definitions and bring them into MATLAB.

The following table describes the data types in more detail.

Special Values | Operators |