[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

# 3. Data Types

All versions of Octave include a number of built-in data types, including real and complex scalars and matrices, character strings, and a data structure type.

It is also possible to define new specialized data types by writing a small amount of C++ code. On some systems, new data types can be loaded dynamically while Octave is running, so it is not necessary to recompile all of Octave just to add a new type. See section 13.8 Dynamically Linked Functions, for more information about Octave's dynamic linking capabilities. 3.2 User-defined Data Types describes what you must do to define a new data type for Octave.

Built-in Function: typeinfo (expr)

  Return the type of the expression expr, as a string. If EXPR is omitted, return an array of strings containing all the currently installed data types.

3.1 Built-in Data Types |  |
3.2 User-defined Data Types |  |
3.3 Object Sizes |  |

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

## 3.1 Built-in Data Types

The standard built-in data types are real and complex scalars and matrices, ranges, character strings, and a data structure type. Additional built-in data types may be added in future versions. If you need a specialized data type that is not currently provided as a built-in type, you are encouraged to write your own user-defined data type and contribute it for distribution in a future release of Octave.

3.1.1 Numeric Objects |  |
3.1.2 Missing Data |  |
3.1.3 String Objects |  |
3.1.4 Data Structure Objects |  |

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### 3.1.1 Numeric Objects

Octave's built-in numeric objects include real and complex scalars and matrices. All built-in numeric data is currently stored as double precision numbers. On systems that use the IEEE floating point format, values in the range of approximately 2.2251e-308 to 1.7977e+308 can be stored, and the relative precision is approximately 2.2204e-16. The exact values are given by the variables `realmin`, `realmax`, and `eps`, respectively.

Matrix objects can be of any size, and can be dynamically reshaped and resized. It is easy to extract individual rows, columns, or submatrices using a variety of powerful indexing features. See section 10.1 Index Expressions.

See section 4. Numeric Data Types, for more information.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### 3.1.2 Missing Data

Built-in Variable: NA
  Missing value.

Mapping Function: isna (x)
  Return 1 for elements of x that are NA (missing) values and zero otherwise. For example,

      is_NA ([13, Inf, NA, NaN])
           => [ 0, 0, 1, 0 ]

Mapping Function: is_nan_or_na (x)
  Return 1 for elements of x that are NaN or NA (missing) values and zero otherwise. For example,

      is_NAN_or_NA ([13, Inf, NA, NaN])
           => [ 0, 0, 1, 1 ]

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### 3.1.3 String Objects

A character string in Octave consists of a sequence of characters enclosed in either double-quote or single-quote marks. Internally, Octave currently stores strings as matrices of characters. All the indexing operations that work for matrix objects also work for strings.

See section 5. Strings, for more information.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### 3.1.4 Data Structure Objects

Octave's data structure type can help you to organize related objects of different types. The current implementation uses an associative array with indices limited to strings, but the syntax is more like C-style structures.

See section 6. Data Structures, for more information.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

## 3.2 User-defined Data Types

Someday I hope to expand this to include a complete description of Octave's mechanism for managing user-defined data types. Until this feature is documented here, you will have to make do by reading the code in the ``ov.h`', ``ops.h`', and related files from Octave's ``src`' directory.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

## 3.3 Object Sizes

The following functions allow you to determine the size of a variable or expression. These functions are defined for all objects. They return -1 when the operation doesn't make sense. For example, Octave's data structure type doesn't have rows or columns, so the `rows` and `columns` functions return -1 for structure arguments.

Function File: columns (a)
  Return the number of columns of a.

Function File: rows (a)
  Return the number of rows of a.

Built-in Function: length (a)
  Return the `length' of the object a. For matrix objects, the length is the number of rows or columns, whichever is greater (this odd definition is used for compatibility with Matlab).

Built-in Function: size (a, n)
  Return the number rows and columns of a.

  With one input argument and one output argument, the result is returned in a row vector. If there are multiple output arguments, the number of rows is assigned to the first, and the number of columns to the second, etc. For example,

      size ([1, 2; 3, 4; 5, 6])
           => [ 3, 2 ]

      [nr, nc] = size ([1, 2; 3, 4; 5, 6])
           => nr = 3
           => nc = 2

  If given a second argument, `size` will return the size of the corresponding dimension. For example

      size ([1, 2; 3, 4; 5, 6], 2)
           => 2

  returns the number of columns in the given matrix.

Built-in Function: isempty (a)
  Return 1 if a is an empty matrix (either the number of rows, or the number of columns, or both are zero). Otherwise, return 0.

[ << ] | [ >> ] |  |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

This document was generated by John W. Eaton on May, 18 2005 using texi2html