# Documentation

### This is machine translation

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

# length

Length of largest array dimension

## Syntax

• ``L = length(X)``
example

## Description

example

````L = length(X)` returns the length of the largest array dimension in `X`. For vectors, the length is simply the number of elements. For arrays with more dimensions, the length is `max(size(X))`. The length of an empty array is zero.```

## Examples

collapse all

Find the length of a uniformly spaced vector in the interval `[5,10]`.

```v = 5:10 ```
```v = 5 6 7 8 9 10 ```
```L = length(v) ```
```L = 6 ```

Find the length of a 3-by-7 matrix of zeros.

```X = zeros(3,7); L = length(X) ```
```L = 7 ```

Create a structure with fields for `Day` and `Month`. Use the `structfun` function to apply `length` to each field.

```S = struct('Day',[1 13 14 26],'Month',{{'Jan','Feb', 'Mar'}}) ```
```S = struct with fields: Day: [1 13 14 26] Month: {'Jan' 'Feb' 'Mar'} ```
```L = structfun(@(field) length(field),S) ```
```L = 4 3 ```

## Input Arguments

collapse all

Input array, specified as a numeric array, character array, logical array, structure, cell array, categorical array, datetime array, duration array, or calendarDuration array.

`length` does not operate on tables. To examine the dimensions of a table, use the `height`, `width`, or `size` functions.

Complex Number Support: Yes

collapse all

### Tall Array Support

This function fully supports tall arrays. For more information, see Tall Arrays.

Watch now