Object Sizes - GNU Octave
Description: GNU Octave

Previous: User-defined Data Types, Up: Data Types

### 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.

— Built-in Function: ndims (a)

> Return the number of dimensions of a. For any array, the result will always be larger than or equal to 2. Trailing singleton dimensions are not counted.

>                 ndims (ones (4, 1, 2, 1)
>                    ⇒ 3

— Built-in Function: columns (a)

> Return the number of columns of a.

> See also: rows, size, length, numel, isscalar, isvector, ismatrix.

— Built-in Function: rows (a)

> Return the number of rows of a.

> See also: columns, size, length, numel, isscalar, isvector, ismatrix.

— Built-in Function: numel (a)
— Built-in Function: numel (a, idx1, idx2, ...)

> Return the number of elements in the object a. Optionally, if indices idx1, idx2, ... are supplied, return the number of elements that would result from the indexing

>                 a(idx1, idx2, ...)

> This method is also called when an object appears as lvalue with cs-list indexing, i.e., `object{...}` or `object(...).field`.

> See also: size.

— 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)
— Built-in Function: size (a, dim)

> Return the number of 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.

> See also: numel.

— Built-in Function: isempty (a)

> Return true if a is an empty matrix (any one of its dimensions is zero). Otherwise, return false.

> See also: isnull.

— Built-in Function: isnull (x)

> Return true if x is a special null matrix, string, or single quoted string. Indexed assignment with such a value on the right-hand side should delete array elements. This function should be used when overloading indexed assignment for user-defined classes instead of `isempty`, to distinguish the cases:

> `A(I) = []`
>   This should delete elements if `I` is nonempty.
> `X = []; A(I) = X`
>   This should give an error if `I` is nonempty.

> See also: isempty, isindex.

— Built-in Function: sizeof (val)

> Return the size of val in bytes.

> See also: whos.

— Built-in Function: size_equal (a, b, ...)

> Return true if the dimensions of all arguments agree. Trailing singleton dimensions are ignored. Called with a single or no argument, size_equal returns true.

> See also: size, numel.

— Built-in Function: squeeze (x)

> Remove singleton dimensions from x and return the result. Note that for compatibility with matlab, all objects have a minimum of two dimensions and row vectors are left unchanged.