Products & Services Solutions Academia Support User Community Company

Learn more about MATLAB   

Overview of MATLAB Classes

Fundamental MATLAB Classes

There are many different data types, or classes, that you can work with in the MATLAB software. You can build matrices and arrays of floating-point and integer data, characters and strings, and logical true and false states. Function handles connect your code with any MATLAB function regardless of the current scope. Structures and cell arrays, provide a way to store dissimilar types of data in the same array.

There are 15 fundamental classes in MATLAB. Each of these classes is in the form of a matrix or array. This matrix or array is a minimum of 0-by-0 in size and can grow to an n-dimensional array of any size.

All of the fundamental MATLAB classes are circled in the diagram below:

Numeric classes in the MATLAB software include signed and unsigned integers, and single- and double-precision floating-point numbers. By default, MATLAB stores all numeric values as double-precision floating point. (You cannot change the default type and precision.) You can choose to store any number, or array of numbers, as integers or as single-precision. Integer and single-precision arrays offer more memory-efficient storage than double-precision.

All numeric types support basic array operations, such as subscripting and reshaping. All numeric types except for int64 and uint64 can be used in mathematical operations.

You can create two-dimensional double and logical matrices using one of two storage formats: full or sparse. For matrices with mostly zero-valued elements, a sparse matrix requires a fraction of the storage space required for an equivalent full matrix. Sparse matrices invoke methods especially tailored to solve sparse problems

These classes require different amounts of storage, the smallest being a logical value or 8–bit integer which requires only 1 byte. It is important to keep this minimum size in mind if you work on data in files that were written using a precision smaller than 8 bits.

How to Use the Different Classes

The following table describes these classes in more detail.

Class Name

Documentation

Intended Use

double, singleFloating-Point Numbers
  • Required for fractional numeric data.

  • Double and Single precision.

  • Range = 2.2251e-308 to 1.7977e+308.

  • Two-dimensional arrays can be sparse.

  • Default numeric type in MATLAB.

int8, uint8,
int16, uint16,
int32, uint32,
int64, uint64
Integers
  • Use for signed and unsigned whole numbers.

  • More efficient use of memory.

  • Range = -263 to 263-1 (64 bit), -231 to 231-1 (32 bit)

  • Choose from 4 sizes (8, 16, 32, and 64 bits).

  • Use all but 64-bit in mathematics operations.

charCharacters and Strings
  • Required for text.

  • Native or unicode.

  • Converts to/from numeric.

  • Use with regular expressions.

  • For multiple strings, use cell arrays.

logicalLogical Class
  • Use in relational conditions or to test state.

  • Can have one of two values: true or false.

  • Also useful in array indexing.

  • Two-dimensional arrays can be sparse.

function_handleFunction Handles
  • Pointer to a function.

  • Enables passing a function to another function

  • Can also call functions outside usual scope.

  • Useful in Handle Graphics callbacks.

  • Save to MAT-file and restore later.

structStructures
  • Fields store arrays of varying classes and sizes.

  • Access multiple fields/indices in single operation.

  • Field names identify contents.

  • Simple method of passing function arguments.

  • Use in comma-separated lists for efficiency.

  • More memory required for overhead

cellCell Arrays
  • Cells store arrays of varying classes and sizes.

  • Allows freedom to package data as you want.

  • Manipulation of elements is similar to arrays.

  • Simple method of passing function arguments.

  • Use in comma-separated lists for efficiency.

  • More memory required for overhead

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS