Basics

10. Colon

The colon(:) is one of the most useful operators in MATLAB. It can create vectors, subscripts, and specify for loop iterations. The colon operator uses the following rules to create regularly spaced vectors: j:k is the same as [j,j+1,...,k] Below are the definitions that govern the use of the colon to pick out selected rows, columns, and elements of vectors, matrices, and higher-dimensional arrays:

A(:,j)
is the j-th column of A
A(i,:) is the i-th row of A