Written and maintained by CASRAI Editorial Board
Last updated
The “double colon” in MATLAB is the two-colon form start:step:stop, which builds an evenly spaced row vector. MATLAB has no :: operator; the colon operator takes a start, an optional step and a stop, and the default step is 1. This page is for researchers and analysts who need to generate sequences, slice arrays and drive loops with it, and who need to know why 0:0.3:1 does not end at 1.
What it is used for in research
MathWorks documents the colon as an operator that can create vectors, subscript arrays and specify iterations. In analysis scripts that means three recurring jobs: building a time or parameter axis (t = 0:0.1:10), selecting rows or columns of a data matrix (A(:,2:3)), and looping over indices (for n = 1:4). The same character does all three, which is why the forms are easy to confuse.
| Form | Meaning | Role |
|---|---|---|
j:k |
Vector from j to k in steps of 1 | Vector creation |
j:i:k |
Vector from j to k in steps of i (the “double colon” form) | Vector creation |
A(:,n), A(m,:) |
Column n, row m of A | Indexing |
A(j:k) |
Elements j through k of A | Indexing |
A(:) |
All elements of A as one column vector | Indexing / reshape |
for n = j:k |
Iterate n over the vector | Loop iteration |
Install or access (official source only)
The colon operator is built into the MATLAB language, so no toolbox or add-on is needed. Obtain MATLAB from MathWorks (mathworks.com/products/matlab.html) and use the official reference page for the operator, Colon, for the exact current syntax. Many institutions provide campus licences; check with your research computing or IT office.
Step-by-step: build and use a start:step:stop vector
- Create a vector with the default step of 1:
x = 1:10returns the integers 1 through 10 (a 1-by-10 row vector). - Add a step as the middle value:
x = 0:2:10returns0 2 4 6 8 10(1-by-6). - Count down with a negative step:
x = 6:-1:0returns6 5 4 3 2 1 0(1-by-7). MathWorks states that to decrement you use a negative number. - Use a fractional step:
x = 1:0.2:2.1returns1.0 1.2 1.4 1.6 1.8 2.0(1-by-6). The sequence ends at the last value it can reach before exceeding the range, so 2.1 is not included. - Select from a matrix: for a 3-by-3 matrix
A,A(1,:)is the first row,A(:,2:3)is columns 2 and 3, andA(:)is a 9-by-1 column. - Loop over the vector:
for n = 1:4runs the loop body four times with n = 1, 2, 3, 4. See loops in MATLAB for the full loop syntax.
Output and how to read it
The result of j:i:k is a row vector, so the size is always 1-by-N. Read the count from the size, not from the arithmetic you expect: -2.5:2.5 gives -2.5 -1.5 -0.5 0.5 1.5 2.5, which is 1-by-6. To get a column instead, transpose the result or index with A(:) on an existing array. For how indexing works once you have the vector, see indexing in MATLAB, and for building and combining arrays see matrices in MATLAB.
Empty and floating-point results
When the result is empty
Per the MathWorks reference, j:k is empty when j is greater than k. j:i:k is empty when any input is empty, when i is 0, when i is positive and j is greater than k, or when i is negative and j is less than k. A positive step with a start above the stop (10:2:0) therefore returns an empty vector rather than an error; use 10:-2:0 to count down.
The non-integer step trap
With a non-integer increment, floating-point arithmetic decides whether the endpoint is included. MathWorks notes that 0:0.3:1 does not end at 1 (the last element is 0.9). If you need a fixed number of points that includes both endpoints, MathWorks points to linspace instead; see linspace in MATLAB.
Troubleshooting
| Symptom | Cause (per the MathWorks reference) |
|---|---|
Result is 1x0 empty |
Step sign does not match the direction from start to stop, or step is 0 |
| Last expected point is missing | Stop is not reachable in whole steps, or floating-point arithmetic excluded it; use linspace for guaranteed endpoints |
| Got a column when a row was expected | A(:) always returns a column; colon-built vectors are rows |
Free alternatives
If you do not have a MATLAB licence, these tools express the same idea. Syntax differs, so check each project’s own documentation.
| Tool | Equivalent | Note |
|---|---|---|
| GNU Octave | 1:3:5 |
The Octave manual (v9.2.0, “Ranges”) defines a range by base, optional increment and a limit the elements do not exceed, with default increment 1; 1:3:5 gives [1, 4] |
| Python / NumPy | numpy.arange(start, stop, step) |
Stop is exclusive, unlike MATLAB |
| R | seq(from, to, by) |
Base R function |
| Julia | start:step:stop |
Same order of arguments as MATLAB |
FAQ
Is there a :: operator in MATLAB?
No. “Double colon” refers to the two colons in start:step:stop. A single colon (j:k) uses the default step of 1.
What does A(:) do?
It reshapes all elements of A into a single column vector, and has no effect if A is already a column.
How do I count down?
Use a negative step, for example 10:-2:0.
Sources (official docs)
- MathWorks, Colon (read 2026-11-07)
- MathWorks, Creating, Concatenating, and Expanding Matrices (read 2026-11-07)
- MathWorks, MATLAB Operators and Special Characters (read 2026-11-07)
- GNU Octave manual 9.2.0, Ranges (read 2026-11-07)







