| MATLAB C++ Math Library | Search  Help Desk |
| colon | See Also |
Generate a sequence of indices
C++ Prototype
mwIndex colon(); mwIndex colon(mwArray start, mwArray end); mwIndex colon(mwArray start, mwArray step, mwArray end);
Arguments
startC++ Syntax
B = A(colon());B = A(colon(1,10));B = A(colon(1,2,10));
MATLAB Syntax
colon = start:stop colon = start:step:stop
Description
colon() generates a "sequence" of indices. colon() stands for "every value." For example, A(colon()) means every value in arrayA. A(1,colon()) means every column in the first row.
colon(start, end) generates a vector of (end - start) + 1 elements. The elements in the vector are start, start+1, start+2, , start+n, end. Each element in the vector is one greater than the preceding element. Iteration stops when the start+n is larger than end, yet the last value in the vector is always end. This can decrease the distance between the last two elements to less than 1.
colon(start, step, end) generates a vector of ((end - start)/step) + 1 elements. The elements in the vector are start, start+step, start+(2*step), start+(3*step), , start+(n*step), end. Iteration stops when the start+(n*step) is larger than end, yet the last value in the vector is always end. This can decrease the distance between the last two elements to less than step. Specifying a negative step generates a decreasing sequence. Specifying a sequence that will not terminate raises an exception.
See Also
colon Calling Conventions