# colon, :

Create vectors, array subscripting

## Description

returns
a regularly-spaced vector, [j, j+1 ,..., k]. `y`

= `j`

:`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
```

.

## Examples

### Use fi as a Colon Operator

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.

### Use the colon Operator With Signed and Unsigned Operands

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.

### Create a Vector of Decreasing Values

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

### Use the colon Operator With Floating-Point and fi Operands

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.

### Rewrite Code That Uses Non-Integer Operands

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;

### All Colon Operands Must Be in the Range of the Data Type

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

`j`

— Beginning operand

real scalar

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`

`i`

— Increment

1 (default) | real scalar

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`

`k`

— Ending operand

real scalar

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

`y`

— Regularly-spaced vector

real vector

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`

.

**Introduced in R2013b**

## Open Example

You have a modified version of this example. Do you want to open this example with your edits?

## MATLAB Command

You clicked a link that corresponds to this MATLAB command:

Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

# Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

## How to Get Best Site Performance

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

### Americas

- América Latina (Español)
- Canada (English)
- United States (English)

### Europe

- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)

- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)