# colon, :

Create vectors, array subscripting

## Syntax

``y = j:k``
``y = j:i:k``

## Description

example

````y = j:k` returns a regularly-spaced vector, [j, j+1 ,..., k]. `j:k` is empty when `j > k`.At least one of the colon operands must be a `fi` object. All colon operands must have integer values. All the fixed-point operands must be binary-point scaled. Slope-bias scaling is not supported. If any of the operands is complex, the `colon` function generates a warning and uses only the real part of the operands.`y = colon(j,k)` is the same as ```y = j:k```.```

example

````y = j:i:k` returns a regularly-spaced vector, `[j,j+i,j+2i, ...,j+m*i]`, where `m = fix((k-j)/i)`. `y = j:i:k` returns an empty matrix when`i == 0`, `i > 0` and``` j > k```, or `i < 0` and ```j < k```.```

## Examples

collapse all

When you use `fi` as a colon operator, all colon operands must have integer values.

```a = fi(1,0,3,0); b = fi(2,0,8,0); c = fi(12,0,8,0); x = a:b:c```
```x = 1 3 5 7 9 11 DataTypeMode: Fixed-point: binary point scaling Signedness: Unsigned WordLength: 8 FractionLength: 0 ```

Because all the input operands are unsigned, `x` is unsigned and the word length is 8. The fraction length of the resulting vector is always 0.

```a= fi(int8(-1)); b = uint8(255); c = a:b; len = c.WordLength```
```len = 9 ```
`signedness = c.Signedness`
```signedness = 'Signed' ```

The word length of `c` requires an additional bit to handle the intersection of the ranges of `int8` and `uint8`. The data type of `c` is signed because the operand `a` is signed.

If the beginning and ending operands are unsigned, the increment operand can be negative.

`x = fi(4,false):-1:1`
```x = 4 3 2 1 DataTypeMode: Fixed-point: binary point scaling Signedness: Unsigned WordLength: 16 FractionLength: 0 ```

If any of the operands is floating-point, the output has the same word length and signedness as the `fi` operand

`x = fi(1):10`
```x = 1 2 3 4 5 6 7 8 9 10 DataTypeMode: Fixed-point: binary point scaling Signedness: Signed WordLength: 16 FractionLength: 0 ```

`x = fi(1):10` is equivalent to `fi(1:10, true, 16, 0)` so `x` is signed and its word length is 16 bits.

If your code uses non-integer operands, rewrite the colon expression so that the operands are integers.

The following code does not work because the colon operands are not integer values.

```Fs = fi(100); n = 1000; t = (0:1/Fs:(n/Fs - 1/Fs));```

Rewrite the colon expression to use integer operands.

```Fs = fi(100); n = 1000; t = (0:(n-1))/Fs;```

If the value of any of the colon operands is outside the range of the data type used in the colon expression, MATLAB® generates an error.

` y = fi(1,true,8,0):256`

MATLAB generates an error because 256 is outside the range of `fi(1,true, 8,0)`. This behavior matches the behavior for built-in integers. For example, `y = int8(1):256` generates the same error.

## Input Arguments

collapse all

Beginning operand, specified as a real scalar integer-valued `fi` object or built-in numeric type.

If you specify non-scalar arrays, MATLAB interprets `j:i:k` as `j(1):i(1):k(1)`.

Data Types: `fi` |`single` | `double` | `int8` | `int16` | `int32` | `int64` | `uint8` | `uint16` | `uint32` | `uint64`

Increment, specified as a real scalar integer-valued `fi` object or built-in numeric type. Even if the beginning and end operands, `j` and `k`, are both unsigned, the increment operand `i` can be negative.

Data Types: `fi` |`single` | `double` | `int8` | `int16` | `int32` | `int64` | `uint8` | `uint16` | `uint32` | `uint64`

Ending operand, specified as a real scalar integer-valued `fi` object or built-in numeric type.

Data Types: `fi` |`single` | `double` | `int8` | `int16` | `int32` | `int64` | `uint8` | `uint16` | `uint32` | `uint64`

## Output Arguments

collapse all

Fixed-Point Designer™ determines the data type of the `y` using the following rules:

• The data type covers the union of the ranges of the fixed-point types of the input operands.

• If either the beginning or ending operand is signed, the resulting data type is signed. Otherwise, the resulting data type is unsigned.

• The word length of `y` is the smallest value such that the fraction length is 0 and the real-world value of the least-significant bit is 1.

• If any of the operands is floating-point, the word length and signedness of `y` is derived from the `fi` operand.

• If any of the operands is a scaled double, `y` is a scaled double.

• The `fimath` of `y` is the same as the `fimath` of the input operands.

• If all the `fi` objects are of data type `double`, the data type of `y` is `double`. If all the `fi` objects are of data type `single`, the data type of `y` is `single`. If there are both `double` and `single` inputs, and no fixed-point inputs, the output data type is `single`.

## Version History

Introduced in R2013b